Boost logo

Boost :

From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2008-03-03 13:08:01


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Monday 11 February 2008 10:11 am, Johan Torp wrote:
> I'm wondering if the new thread safe implementation of signals guarantees
> atomic disconnects.
>
> line1: signal<void(), multi_threaded> sig;
> line2: thread t(sig); // Start a new thread which will emit "sig"
> line3: sig.connect(&some_func);
> line4: sig.disconnect(&some_func);
> line5: ...
>
> Am I guaranteed that some_func isn't called at line 5 or afterwards?

Sorry it took me so long to reply to this, I just noticed it. If some_func is
in the process of running in another thread when you call disconnect(), it
may still be running when disconnect() returns. disconnect() does not block
waiting for any slots to complete. In fact, no mutexes inside the signal are
held while a slot is executing, to avoid deadlock issues.

> If disconnect is blocking, how do you prevent the following dead-lock
> during signal emission?
> - Emitting thread tries to acquire a mutex X via a slot
> - Disconnect calling thread is holding X and gets blocked on disconnect

- --
Frank
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHzD6K5vihyNWuA4URAnk8AKCvf2Ldcn4QHBWwyCCFVAhSnyPeEQCeIPOK
f2DFJgH45x5lArF1EJPelPw=
=Gq8c
-----END PGP SIGNATURE-----


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk