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

Re: [Libevent-users] Trivial Example of Multi-Thread Issue

On Thu, Oct 24, 2013 at 2:02 PM, Dave Zielinski
<DZielinski@xxxxxxxxxxxxxxxxx> wrote:
> Hi guys,
>   I’ve been trying to track down a bug with multi-thread use of libevent.
> I’m only using the timeout feature of libevent (no fd’s).  I’ve dumbed down
> the issue to a simple example which is copied in below.    This code
> deadlocks waiting for the event to occur.

event_base_dispatch() returns immediately if there are no events added
to the event base, and no events active in the event base. When you
call it from thread 2, there are no events (yet) added to the event
base, and so it's going to return before thread 1 actually adds an

You can override this behavior with the EVLOOP_NO_EXIT_ON_EMPTY flag
in Libevent 2.1.  In libevent 2.0, you can work around it by adding an
dummy event -- say, one with a long periodic timer and a callback that
does nothing.

To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.