A
Alo Sarv
Xenos said:sleep does not change the priority of a process in Window, nor in any other
system I know of.
DrX
I think I failed to make my intentions clear, so let me clarify:
The application is singlethreaded, all events are received from
sockets. The purpose of sleep() was to wake up at some interval, check
if there is anything to process from sockets, and then go back to
sleep. I don't see a way to make the system blocking without coupling
event engine directly with sockets. Additionally, there might pending
jobs that take long time (checksumming files for example), that should
be done in small amounts (64k blocks for example) during event loops.
Or there could be jobs that need to be done at specific intervals (for
example, autosaving config file every 20 minutes). Thus blocking
the loop if there are no socket events isn't an option, since that
would also block those jobs. Removing the sleep() from the loop causes
the loop to run as fast as possible, thus using 100% CPU (on any
system/compiler).
One option that was pointed out in this thread was to loop around
until there are events to process, and then go to sleep for a minimum
delay. Now, if an event handler function posts a new event, that event
also needs to be processed. And if a handler for the new event also
posts a event, that one also needs to be processed, thus can cause
endless loop if the user of the event system isn't careful... Ok, this
could be countered by limiting the number of runs through event loop
w/o sleeping to some amount, after which a sleep will be forced. Can't
say I'm exactly thrilled with this solution.
Alo.