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.
-Steve
harry wrote:
It's unsafe for two threads to call event_init() in parallel because
it sets and returns the global current_base variable. If the first
thread gets preempted by the second after calloc() but before the
return, both calls will return the same value.
My question is whether one should be concerned about the use of
current_base in other parts of the code. For example, event_set()
uses current_base while setting the priority. Is there any chance
that a preemption will occur in the middle of retrieving the value of
current_base resulting in an invalid pointer?
Also, I assume that each process that loads libevent as a shared
object must get its own copy of current_base, right?
Harry
_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkey.org/mailman/listinfo/libevent-users
_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkey.org/mailman/listinfo/libevent-users