[Libevent-users] Threading support question

Patrick Clochesy pcloches at gmail.com
Fri Jun 8 19:15:22 EDT 2007


Thanks. I actually found SPServer shortly after I took a look at this,
and it helped me out a great bit.

One thing I noticed though, was that its event queue for the threads
uses a socketpair for waking up the queue. I implemented it using
pthread_cond_wait and a lock it runs about 3 times faster.

Stephen, if you'd like the code (not hat you couldn't figure it out,
but it took me some debugging to figure out the "proper" way to use
pthread_cond_wait for event queues, drop me a line. Thanks for the
great work!

Thanks,
-Patrick

On 08/06/07, liusifan <liusifan at gmail.com> wrote:
> Hi, Patrick Clochesy
>
> I guess you need a half-aync/half-sync thread pool.
> The main event loop thread (half-async) "handles all the accepts",
> and the "two other types of threads" (half-sync) are in charge of authenticating.
>
> If so, i suggest you to take a look for the SPServer .
>
> > SPServer is a server framework, it implements:
> > 1.An Accepter for TCP Server
> > 2.An asynchronous layer. It has only one thread ( event loop thread ),
> > 3.A synchronous layer. It has multiple threads.
> > 4.A queue between asynchronous layer and synchronous layer.
>
> http://code.google.com/p/spserver/
> http://spserver.googlecode.com/files/spserver-0.3.src.tar.gz
>
>
> Best regards,
>
> liusifan
> 2007-06-08
>
> >>>Here's a quick synopsis for those who don't want to read the whole
> >explanation :) Is it possible to create events in threads that will
> >fire in the main thread if the access to event_set is mutually
> >exclusive?
> >
> >Longer explanation:
> >After I already implemented a multithreaded server based on libevent,
> >I saw Steven's message about the threading support. I basically have
> >one thread which does all the I/O, two other types of threads.
> >
> >The first handles all the accepts and sends a welcome message to each
> >new thread (using libevent if the call to write() doesn't write all
> >the bytes). The second is actually a group of threads which are in
> >charge of authenticating.
> >
> >I had planned on all the threads being able to be able to create new
> >write events using libevent, since the accept()ing threads need to
> >send the protocol "welcome" and also create a read event for when data
> >arrives, and the authentication threads need to send back to the
> >client whether they authenticated or not.
> >
> >However, before having seen this I implemented it, and the event_set
> >in the accept() thread is creating an event that is fired in the main
> >threads event_dispatch(). So, is it okay to continue on this path if I
> >assure the access of the libevent objects are mutually exclusive?
> >
> >Thanks,
> >-Patrick
> >_______________________________________________
> >Libevent-users mailing list
> >Libevent-users at monkey.org
> >http://monkey.org/mailman/listinfo/libevent-users
>
>
>


More information about the Libevent-users mailing list