[Libevent-users] Newbie question about threads

Victor victor.box2 at globo.com
Mon Aug 6 00:09:12 EDT 2007


Hi Mark,

On Monday 06 August 2007, Mark Heily wrote:
> On Sun, 2007-08-05 at 15:31 -0300, Victor wrote:
> > Is it safe to call event_add() from a second thread to
> > add more events on that event loop base?
>
> No. Two threads cannot modify the same event_base struct without
> explicit locking. You would need to use a mutex to protect the
> event_add() call.
>

After reading your email, I thought that just adding mutex around
event_add() will still not be safe, because when a event is
processed, it is removed from the event queue and I cannot lock a
mutex on that from outside libevent, am I right?


Thanks for your answer.

Victor


More information about the Libevent-users mailing list