1 Oct 2008 22:33
Issue with evsignal_base in event_base_loop
Lance Lovette <lance_lovette <at> hotmail.com>
2008-10-01 20:33:36 GMT
2008-10-01 20:33:36 GMT
I'm running my application (using libevent 1.4.8) through the Valgrind tool
Helgrind to help make sure I have no race conditions. It brought my
attention to the following line of code in event_base_loop (line 475 in the
current release, line 698 in trunk), that after inspection is confusing to
me.
if (&base->sig.ev_signal_added)
evsignal_base = base;
If I'm reading this correctly, the statement "&base->sig.ev_signal_added"
evaluates to an address, so the condition is always true. Am I missing
something? Is this the desired behavior of this statement?
(As background, the issue that Helgrind reports is triggered by the fact
that I have two threads, each with their own event loop run by
event_base_loop. Since evsignal_base is shared between the two threads (it's
global) they both set it to their thread-local base, and Helgrind
accordingly reports the possibility of a race condition.)
Thanks!
Lance
I suppose most typical libevent applications just sit in
event_base_loop() forever until termination. In this typical case, the
tv_cache is getting refreshed frequently enough so that it's not too
old. (Assuming callbacks don't take excessively long)
Intuitively, I would think that event_set/add() could get called
before and during event_dispatch(). And when no more events need
to be monitored, event_dispatch() returns and the event_base should
be back in its "initial" state, ready to be reused if needed.
Right now, it seems I'd have to call event_init() again to
create a new event_base with a blank tv_cache. (Not to mention
calling event_base_free() to dispose of the original event_base.)
This seems like overkill...
Your thoughts?
Victor
RSS Feed