Simplest threaded example
Marc Lehmann
schmorp at schmorp.de
Tue Aug 3 23:34:01 CEST 2010
On Tue, Aug 03, 2010 at 01:38:33PM +0200, Hongli Lai <honglilai at gmail.com> wrote:
> Well I see that you're using the same event loop in all worker
> threads. That's obviously not gonna work.
It is as long as he locks. In fact, this is a common pattern in threaded
design called leader-follower, where one thread runs the event loop until
it becomes busy, and another takes over from then.
It's not trivial, and by all means I don't know if that is what he intends
to implement.
> What you could do for example is to accept() connections from the main
> thread, and for each accepted connection spawn a worker thread that
> handles that connection only. Each worker thread must have its own
> loop, you can't share loops between threads.
Depending on the problem, this can be extremely inefficient (or even
impossible, if you need a larger number of threads).
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / schmorp at schmorp.de
-=====/_/_//_/\_,_/ /_/\_\
More information about the libev
mailing list