Use a separate thread to process events.

Introduced POSIX threads to process events. In an implementation without
threads, events may be read from the network after all user callbacks
have been executed. This makes impossible to properly set the timestamp
for those events, and impossible to process them when they are generated.

With this new approach, a thread will be responsible of reading new
events from the network and storign them in an event queue, and an event
dispatcher thread is responsible of consuming the event queue to process
the events and calling the user callbacks.