[Libevent-users] event_init() and thread safety
harry
hkao-co at appliedminds.com
Tue May 1 14:45:37 EDT 2007
On Tue, May 01, 2007 at 10:38:50AM -0700, Steven Grimm wrote:
> If you're calling event_init() more than once, you never want to call
> event_set() and other such functions. You want to call event_set_base()
> and pass in the handle you get back from event_init(). Using the
> current_base versions of the event calls in a multithreaded app (where
> you are using libevent from multiple threads in parallel) is almost
> certainly going to break your app.
>
> In the MT version of memcached I call event_init() in my startup thread
> and pass the handle to each of the worker threads I spawn. That way
> there's no chance of race conditions during initialization.
Thanks for the response. I don't see an event_set_base() function.
Do you mean event_base_set()? My understanding is that you call
event_set() to initialize the event structure and then call
event_base_set() to change the event's base from current_base to
whatever you got back from event_init(). Is this incorrect?
Harry
More information about the Libevent-users
mailing list