Event Loop

An event loop is a loop that waits for events to happen and then directs them to specific functions to handle.

See Wikipedia.

In an event loop if we:

  • Put slow code into the thread which is running the message loop

  • Then this will hurt the performance and responsiveness of the program

  • Typically because CPUs are super super fast, slow code generally means code which is performing input/output operations (I/O operations) - i.e. writing/reading to file, waiting for data to arrive over a network etc.

So if we are writing code on a thread that we know is running an event loop, then it is generally a bad idea to to put those IO operations directly on to that thread. Instead the techniques we should use are:

  • Put those blocking I/O operations on to separate threads

  • Use asynchronous libraries which don’t block but instead provide call backs (via the event loop mechanism) when the operations are completed.

In Iguana historically we have had one main thread which runs an event loop based on “select”. Unfortunately there is a lot of blocking I/O which happens in Iguana’s main thread since it wasn’t clear to a lot of people that worked on the code base over time that this wasn’t a good idea.

We have changed IguanaX over to a more modern event loop foundation.

See:

 

Related pages