An efficient event loop implementation? -
An efficient event loop implementation? -
possible duplicate: how implement basic event-loop?
not language-specific question. efficient implementation of event loop? far i've encountered this:
while (true) { handleevents(); sleep(100); }
which don't think best way - if sleep duration short, eat lots of cpu, , if it's long, app pretty unresponsive.
so, there improve way?
thanks
the mutual pattern is:
while (waitfornextevent()) { handleevent(); }
with waitfornextevent()
returning false
indicate there no more events process, and, importantly, beingness able perform blocking wait next event.
for instance, event source might file, socket, thread's message queue or waitable object of kind. in case, can guarantee handleevent()
runs if event ready, , triggered shortly after event becomes ready.
events event-loop
Comments
Post a Comment