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

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -