Hey all, I just joined the list after noticing that there was discussion regarding libevent usage within threaded applications.
I've implemented my own solution built on top of libevent that allows me to pass messages to a thread-specific event loop. I have a model similar to what William Ahern described where I have a listener thread that accepts inbound connections and then feeds them off to my multiple "worker" threads. The listener thread has to do a little work to determine which worker should receive the new connection but the overhead is negligible. Each worker thread is running its own event loop with event_base_dispatch. I create a socketpair, a mutex, and a message queue (of void pointers) for each worker thread. To send a message to a specific thread I lock the mutex, add the message to the queue, and write a byte down the right end of the socketpair if the queue was empty. Each worker has a persistent read event registered on its side of the socketpair and calls a callback that reads the byte, locks the queue, pops all the pending messages off the queue and processes them, etc. Using this solution I get the benefit of balancing clients across multiple threads and can still use libevent within that thread for polling and timeouts. I've been very pleased with the overall performance so far. I've been meaning to turn my existing code in to a library so I can more easily use it in future applications. I'd be happy to share what I come up with if anyone is interested in seeing it. I'm not sure if it would make sense to roll it in to the base libevent code since it has POSIX dependencies but perhaps Neils could make that call if the time comes. Andrew _______________________________________________ Libevent-users mailing list Libevent-users@monkey.org http://monkey.org/mailman/listinfo/libevent-users