Re: ncurses event loop
- From: Wellu <kuumaliimamies@xxxxxxxxx>
- Date: Wed, 26 Sep 2007 07:00:44 -0700
On 26 syys, 16:15, Thomas Dickey <dic...@xxxxxxxxxxxxxxxxxx> wrote:
Wellu <kuumaliimam...@xxxxxxxxx> wrote:
To me this looks weird but that can be due to fact that this is my
first ncurses program :) Anyway.. Is this kind of programming as "bad"
as it looks? Let's say get_progress_info() function takes 10 ms to
respond. That means that CPU-usage would be 100% all the time which is
vey bad thing. Does getch() really sleep when no keypress is coming?
no - getch() will wait at most 10msec before returning.
If there's no keyboard activity that's 50% usage - assuming no other
processes need time (which would be unusual).
Miscalculation indeed.. So it seems that inside getch() the system
really sleeps so doing getch() with decent timeout (e.g 10 ms) would
not bring the processor to its knees.. Anyway, my question was if this
kind of "polling" is the way to go if I'm going to get data from
another process? Should I, for example, create a semaphore that is
signaled once there is something to read? So my FOREVER loop would
only require to test getch() and if there is no keypresses then check
for the semaphore. I would use this semaphore as a flag for "Hey, UI
process! Now there's something to read." This way the actual reading
(might take lots of CPU cycles) won't be called if there is no data..
--
Wellu
.
- References:
- ncurses event loop
- From: Wellu
- Re: ncurses event loop
- From: Thomas Dickey
- ncurses event loop
- Prev by Date: Re: ncurses event loop
- Next by Date: advice on how to detect time change
- Previous by thread: Re: ncurses event loop
- Next by thread: Re: ncurses event loop
- Index(es):