[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] levent 2.x multithreaded?



On Thu, Mar 18, 2010 at 12:52 PM, Roman Puls <puls@xxxxxxxxxxxx> wrote:
> Hi Folks,
>
> I thought libevent would work multithreaded in the sense we can create
> (let's say) 4 worker threads that poll the same event_base. Is that
> assumption wrong?

Yes.

Each event base can only have one thread invoking
event_base_dispatch() on it (or event_base_loop, etc).  Libevent's
multithreading support in 2.0 is such that it's possible to manipulate
an event_base (or most things) from multiple threads (assuming you've
got locking enabled) but the main loop for each event_base still runs
in just a single thread.
If you want to have multiple worker threads, you need to either

1) have a separate event_base for each one
2) have an event_base running in one thread whose callbacks assign
work (through some reasonable model) to the other threads.
3) get Libevent's event_base_dispatch() function to support thread pools.

Long-term, we do indeed hope to do 3, but it almost certainly won't
happen for Libevent 2.0; maybe in 2.1 or 2.2.

-- 
Nick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.