ev_ref, the other way round
schmorp at schmorp.de
Mon Jun 22 23:16:33 CEST 2009
On Mon, Jun 22, 2009 at 04:44:49PM +0200, Gabriel Kerneis <kerneis at pps.jussieu.fr> wrote:
> cooperative, (continuation-based) threads. These threads might be
> blocking the termination. But I also don't want the loop to end when
> every thread is detached, so I ref when detaching and unref when
> attaching a thread.
You can use ev_ref/unref to create _additional_ references as much as
you want, it doesn't matter to libev whether these are watchers or other
reaources it has no clue about. The refcount exists solely to terminate
> Does it sound right? Could I get a busy wait when everybody is detached
> or does the async watcher handle that case nicely?
I don't fully understand this combination - the async watcher itself
keeps a reference, and yes, it's possible to have just an async watcher
(which will keep the loop alive), in which case you wouldn't really need
additional references too.
Also, if the only reason for the async watcher is ev_unref, you can safely
call libev functions from any of your cooperative threads (as long as they
are really cooperative, i.e. ev_loop blocks the process and switching is
done only inside callbacks).
calling ev_ref/unref is safe at any time, though, as long as nothing runs
truly in parallelm even if e.g. poll() is a scheduling point for the
thread lib, as all they do is incrase decrease a counter that is used
inside ev_loop to decide when to exit (a refcnt of zero causes ev_loop to
not poll for events and to return almost instantly).
> [Completely unrelated: I'm a bit concerned that libev includes external
Well, libev cannot work without external functions and datatypes. If you mean
the header file, I cannot guarantee that you will be able to switch it off
(inttypes.h is a good candidate).
> I worked around this by disabling the stats and defining
> EV_ATOMIC_T. Do you have a list of architectures where sig_atomic_t !=
No, but if you find such a list, tell us :)
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / pcg at goof.com
More information about the libev