Resize window in multi-thread ncurses program
Clash Royale CLAN TAG#URR8PPP
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:
Call
endwin
followed byrefresh
in user's ownSIGWINCH
handler.Leverage ncurses builtin
SIGWINCH
handler:getch
aKEY_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:
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?The builtin
SIGWINCH
handler generates aKEY_RESIZE
. But what if there are other keys pressed that haven't been delivered? IsKEY_RESIZE
guaranteed to be the key returned by the next call ofgetch
?Handling
KEY_RESIZE
looks less painful than writing my ownSIGWINCH
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 withgetch
but nothing to do with stdin?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.)?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 theSIGWINCH
signal on the main thread (but not an internal thread created by the ncurses library)?
signals multithreading ncurses
add a comment |
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:
Call
endwin
followed byrefresh
in user's ownSIGWINCH
handler.Leverage ncurses builtin
SIGWINCH
handler:getch
aKEY_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:
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?The builtin
SIGWINCH
handler generates aKEY_RESIZE
. But what if there are other keys pressed that haven't been delivered? IsKEY_RESIZE
guaranteed to be the key returned by the next call ofgetch
?Handling
KEY_RESIZE
looks less painful than writing my ownSIGWINCH
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 withgetch
but nothing to do with stdin?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.)?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 theSIGWINCH
signal on the main thread (but not an internal thread created by the ncurses library)?
signals multithreading ncurses
add a comment |
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:
Call
endwin
followed byrefresh
in user's ownSIGWINCH
handler.Leverage ncurses builtin
SIGWINCH
handler:getch
aKEY_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:
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?The builtin
SIGWINCH
handler generates aKEY_RESIZE
. But what if there are other keys pressed that haven't been delivered? IsKEY_RESIZE
guaranteed to be the key returned by the next call ofgetch
?Handling
KEY_RESIZE
looks less painful than writing my ownSIGWINCH
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 withgetch
but nothing to do with stdin?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.)?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 theSIGWINCH
signal on the main thread (but not an internal thread created by the ncurses library)?
signals multithreading ncurses
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:
Call
endwin
followed byrefresh
in user's ownSIGWINCH
handler.Leverage ncurses builtin
SIGWINCH
handler:getch
aKEY_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:
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?The builtin
SIGWINCH
handler generates aKEY_RESIZE
. But what if there are other keys pressed that haven't been delivered? IsKEY_RESIZE
guaranteed to be the key returned by the next call ofgetch
?Handling
KEY_RESIZE
looks less painful than writing my ownSIGWINCH
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 withgetch
but nothing to do with stdin?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.)?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 theSIGWINCH
signal on the main thread (but not an internal thread created by the ncurses library)?
signals multithreading ncurses
signals multithreading ncurses
edited Dec 17 at 14:53
asked Dec 17 at 14:44
Cyker
1,36121429
1,36121429
add a comment |
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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