Resize window in multi-thread ncurses program

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1














The overall question is simple:



How to gracefully resize a window in a multi-thread ncurses program?




Details here. I have read a few relevant questions (1, 2, 3). From my understanding, there are basically 2 ways to handle a window resize:



  1. Call endwin followed by refresh in user's own SIGWINCH handler.


  2. Leverage ncurses builtin SIGWINCH handler: getch a KEY_RESIZE and handle it.


I have tested on my ncurses implementation to make sure I can receive KEY_RESIZE. But I still don't understand how signal handler works with multi-thread ncurses program:



  1. If I'm using the builtin SIGWINCH handler, which thread will be running the signal handler? Does this matter? Do I have control over this?


  2. The builtin SIGWINCH handler generates a KEY_RESIZE. But what if there are other keys pressed that haven't been delivered? Is KEY_RESIZE guaranteed to be the key returned by the next call of getch?


  3. Handling KEY_RESIZE looks less painful than writing my own SIGWINCH handler. But how can I read this key as soon as it is delivered to make the UI responsive? Can I select or poll stdin to detect its delivery? Is it put on an internal queue that only has something to do with getch but nothing to do with stdin?


  4. If I'm writing my own SIGWINCH handler, do I have any guarantee about ncurses context so that my signal handler code won't break ncurses (by calling functions that cannot be called at the time the signal is delivered, etc.)?


  5. Is ncurses itself single-threaded or multi-threaded? If I block the SIGWINCH signal on all my threads other than the main thread, am I guaranteed to receive the SIGWINCH signal on the main thread (but not an internal thread created by the ncurses library)?










share|improve this question




























    1














    The overall question is simple:



    How to gracefully resize a window in a multi-thread ncurses program?




    Details here. I have read a few relevant questions (1, 2, 3). From my understanding, there are basically 2 ways to handle a window resize:



    1. Call endwin followed by refresh in user's own SIGWINCH handler.


    2. Leverage ncurses builtin SIGWINCH handler: getch a KEY_RESIZE and handle it.


    I have tested on my ncurses implementation to make sure I can receive KEY_RESIZE. But I still don't understand how signal handler works with multi-thread ncurses program:



    1. If I'm using the builtin SIGWINCH handler, which thread will be running the signal handler? Does this matter? Do I have control over this?


    2. The builtin SIGWINCH handler generates a KEY_RESIZE. But what if there are other keys pressed that haven't been delivered? Is KEY_RESIZE guaranteed to be the key returned by the next call of getch?


    3. Handling KEY_RESIZE looks less painful than writing my own SIGWINCH handler. But how can I read this key as soon as it is delivered to make the UI responsive? Can I select or poll stdin to detect its delivery? Is it put on an internal queue that only has something to do with getch but nothing to do with stdin?


    4. If I'm writing my own SIGWINCH handler, do I have any guarantee about ncurses context so that my signal handler code won't break ncurses (by calling functions that cannot be called at the time the signal is delivered, etc.)?


    5. Is ncurses itself single-threaded or multi-threaded? If I block the SIGWINCH signal on all my threads other than the main thread, am I guaranteed to receive the SIGWINCH signal on the main thread (but not an internal thread created by the ncurses library)?










    share|improve this question


























      1












      1








      1


      1





      The overall question is simple:



      How to gracefully resize a window in a multi-thread ncurses program?




      Details here. I have read a few relevant questions (1, 2, 3). From my understanding, there are basically 2 ways to handle a window resize:



      1. Call endwin followed by refresh in user's own SIGWINCH handler.


      2. Leverage ncurses builtin SIGWINCH handler: getch a KEY_RESIZE and handle it.


      I have tested on my ncurses implementation to make sure I can receive KEY_RESIZE. But I still don't understand how signal handler works with multi-thread ncurses program:



      1. If I'm using the builtin SIGWINCH handler, which thread will be running the signal handler? Does this matter? Do I have control over this?


      2. The builtin SIGWINCH handler generates a KEY_RESIZE. But what if there are other keys pressed that haven't been delivered? Is KEY_RESIZE guaranteed to be the key returned by the next call of getch?


      3. Handling KEY_RESIZE looks less painful than writing my own SIGWINCH handler. But how can I read this key as soon as it is delivered to make the UI responsive? Can I select or poll stdin to detect its delivery? Is it put on an internal queue that only has something to do with getch but nothing to do with stdin?


      4. If I'm writing my own SIGWINCH handler, do I have any guarantee about ncurses context so that my signal handler code won't break ncurses (by calling functions that cannot be called at the time the signal is delivered, etc.)?


      5. Is ncurses itself single-threaded or multi-threaded? If I block the SIGWINCH signal on all my threads other than the main thread, am I guaranteed to receive the SIGWINCH signal on the main thread (but not an internal thread created by the ncurses library)?










      share|improve this question















      The overall question is simple:



      How to gracefully resize a window in a multi-thread ncurses program?




      Details here. I have read a few relevant questions (1, 2, 3). From my understanding, there are basically 2 ways to handle a window resize:



      1. Call endwin followed by refresh in user's own SIGWINCH handler.


      2. Leverage ncurses builtin SIGWINCH handler: getch a KEY_RESIZE and handle it.


      I have tested on my ncurses implementation to make sure I can receive KEY_RESIZE. But I still don't understand how signal handler works with multi-thread ncurses program:



      1. If I'm using the builtin SIGWINCH handler, which thread will be running the signal handler? Does this matter? Do I have control over this?


      2. The builtin SIGWINCH handler generates a KEY_RESIZE. But what if there are other keys pressed that haven't been delivered? Is KEY_RESIZE guaranteed to be the key returned by the next call of getch?


      3. Handling KEY_RESIZE looks less painful than writing my own SIGWINCH handler. But how can I read this key as soon as it is delivered to make the UI responsive? Can I select or poll stdin to detect its delivery? Is it put on an internal queue that only has something to do with getch but nothing to do with stdin?


      4. If I'm writing my own SIGWINCH handler, do I have any guarantee about ncurses context so that my signal handler code won't break ncurses (by calling functions that cannot be called at the time the signal is delivered, etc.)?


      5. Is ncurses itself single-threaded or multi-threaded? If I block the SIGWINCH signal on all my threads other than the main thread, am I guaranteed to receive the SIGWINCH signal on the main thread (but not an internal thread created by the ncurses library)?







      signals multithreading ncurses






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 17 at 14:53

























      asked Dec 17 at 14:44









      Cyker

      1,36121429




      1,36121429

























          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489491%2fresize-window-in-multi-thread-ncurses-program%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489491%2fresize-window-in-multi-thread-ncurses-program%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown






          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay