On Fri, Mar 06, 2009 at 09:16:26AM -0500, Brian wrote:
> Thanks Guillaume for the feedback. Unfortunately malloc/calloc method
> didn't work for me. I think I will just go back to how it was. Does
> anyone know if there is an inherent flaw, perhaps, with doing the
> event_init()/event_dispatch() within a posix thread?

Guillaume is right.  In the sample code you posted, the memory used to
hold the "struct event"s on the stack will not continue to be reserved
after the function exits, so a call to another function can totally
overwrite it.  This isn't a pthreads thing.

(To answer your threading question:  in Libevent 1.4.x, it's okay to
do nearly anything from inside a thread, but only one thread can
safely use a given event_base at a time.  Also, if you're using
threads with Libevent 1.4.x, you need to make sure that you always
specify event_base objects explicitly, and use event_base_set on each
new event.  Otherwise, calls to functions will generally use the most
recently initialized event_base, leading to race conditions.)

-- 
Nick

_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users

Reply via email to