[Libevent-users] using threads and event_base... Is this an issue ?

Steven Grimm sgrimm at facebook.com
Wed Mar 7 20:27:41 EST 2007


It looks like this would be a pretty easy problem to fix -- just make 
evsignal_init() check to see if the socketpair has already been 
allocated, and return without doing anything if so. Then you just need 
to make sure your first call to event_init() happens in only one thread. 
(I am assuming here that you don't actually need signal handling; if you 
do, then that first thread's event base would need to be kept around 
since it'd be the only one handling incoming signals.)

Barring that, can you maintain a freelist of event bases and only 
allocate new ones when there aren't any unused ones left? That wouldn't 
fix the underlying bug, but would at least limit your file descriptor 
leakage to 2x the largest number of event bases in use at a time.

-Steve


Massimo Cetra wrote:
> Hi list,
>
> i'm experimenting with libevent in an heavy threaded application.
>
> The application works quite well using all the event_base_ stuff to 
> handle the events in a thread safe way.
>
> My problem is that all the threads that i create have a short life 
> (short as as little as a couple of minutes), so i have to event_init() 
> once in every thread to have an event base struct.
>
> No problem about the methods... the problem arises because even_init() 
> calls evsignal_init() which opens a socket pair which is completely 
> lost and those sockets are never closed.
>
> I end up having a couple of fresh, unused and useless file descriptors 
> for every thread that i have created and there seems no way to close 
> those sockets and sockets are limited...
>
> Am i missing something or is this a known issue ?
>
> This behaviour makes libevent useless for many threaded apps ...
>
> Thanks for your answers...
>
> Massimo Cetra
>
>
> _______________________________________________
> Libevent-users mailing list
> Libevent-users at monkeymail.org
> http://monkey.org/mailman/listinfo/libevent-users



More information about the Libevent-users mailing list