[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] event_base_loop: wait for events to be added by other threads?



I am writing a multi-threaded libevent application. Or rather, I am retrofitting an existing libevent 1.4 application to contain multiple libevent threads. Since the existing code is NOT thread safe, my design is basically to partition the application into N pieces, each with its own event loop. Then I glue the pieces together by scheduling callbacks in appropriate threads using event_active.

There is one small problem: if a thread has no active events, it exits. In my case, I want it to block, waiting for another thread to call event_active to add an event. I have a patch to libevent that fixes this by adding an additional flag to event_base_loop. Is this the "right" solution to this problem?

If so, I have another concern: the three current flags to libevent are actually mutually exclusive. Eg. If you pass EVLOOP_NONBLOCK, that sort of implies EVLOOP_ONCE. Similarly, my new flag is incompatible with EVLOOP_NONBLOCK and EVLOOP_ONCE. Does it make sense to assign each one a bit? Or should the first two bits of flag be the "loop mode"?

00 = normal; run until no active events
01 = EVLOOP_ONCE; wait until one event is triggered then exit
10 = EVLOOP_NONBLOCK; poll the loop once, run highest priority, then exit
11 = EVLOOP_BLOCK_FOR_EXPLICIT_EXIT; run until there is an explicit exit.

Thanks,

Evan Jones

--
Evan Jones
http://evanjones.ca/
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.