Passing data between event loops in multithreaded apps
2009-05-25 12:48
274 查看
[Libevent-users] Re: Passing data between event loops in
multithreaded apps
Andrew Danforthadanforth at gmail.com
Thu Oct 5 21:42:35 EDT 2006
Previous message: [Libevent-users] Can't get event-test.c to work on Mac OS X 10.4.8
Next message: [Libevent-users] Can't get libevent ( event-test.c ) to work on OS
X ( 10.4.8 )!
Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
All, Following up to my own message, I've finalized this code and put it through some unit testing and I'd be interested in any feedback fellow list members may have. I've placed the source on my website @ http://www.weirdness.net/code/libevent Thus far I don't have any documentation however I intend to add some doxygen-based documentation in the future. I'll be particularly motivated to write documentation if someone expresses interest in reading it ;). Thanks, Andrew On 9/11/06, Andrew Danforth <adanforth at gmail.com > wrote: > 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 >
相关文章推荐
- Passing data between pages in JQuery Mobile | Ram's Blog
- visual event recognition in videos by learning from web data
- Multithreaded Work Queue in C++
- Event, Alerts, Perf Data Flow in OpsMgr 2007
- Passing data between view controller.
- Difference between datacontract and messagecontract in wcf
- visual event recognition in videos by learning from web data
- Difference between datacontract and messagecontract in wcf
- Using Collection Classes Safely in Multithreaded Applications
- What Every Dev Must Know About Multithreaded Apps
- Passing Data between View Controllers
- Sharing Data Locally Between iOS Apps
- Solving 11 Likely Problems In Your Multithreaded Code
- visual event recognition in videos by learning from web data
- Kettle笔记之:数据传输(Passing data between transformations)
- ERROR: Error in Log_event::read_log_event(): 'read error', data_len: 234781854, event_type: 2
- Multi-Threaded Libevent Server Example
- Multithreaded simple data type access and atomic variables
- Synchronization in Multithreaded Applications with MFC
- ERROR: Error in Log_event::read_log_event(): 'read error', data_len: 438, event_type: 2