Questions regarding how libev works
schmorp at schmorp.de
Fri Mar 9 08:28:46 CET 2012
On Thu, Mar 08, 2012 at 03:15:30PM -0500, Cong <yuncong at gmail.com> wrote:
> If I don't use multi-threading, do I need to stop accept watcher whenever a
> connection is accepted?
Whether you use multithreading or not, you stop your accept watcher when
you want to stop or pause accepting new connections.
> and it works fine. But I cannot explain how the accept watcher works. If
> there're multiple connection requests received, the accept callback
> function will create a new socket and start a read watcher for each of
libev doesn't have accept watchers, so it's up to whoever wrote the code
you are thinking of to explain what it does and understand it.
> Seems to me this works as if there're multiple "threads", although
> they're not real threads. All these sockets are polled quickly in a loop to
> see if there's any incoming connection, if anyone is readable and if anyone
> is writable. Is my understanding correct?
Probably - the code you are talking about is not part of libev, so it's
hard to tell.
> Seems introducing threads can only add overhead but not benefits. However,
> on a multi-core computer, if the program is not multi-threaded, can the OS
> use multi-core to improve the performance?
threads are not made to improve performance of multi-core chips -
processes were. threads are useful when you need to share large amounts of
data (which is not efficient) or when you have no other good api (which is
also not efficient).
your os will use multiple cores automatically when you have more than one
runnable process (or thread).
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