Boost logo

Boost Users :

Subject: Re: [Boost-users] Signals2 benchmark
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2015-02-06 15:34:15

On Fri, Feb 6, 2015 at 2:23 PM, Niall Douglas <s_sourceforge_at_[hidden]> wrote:
> On 6 Feb 2015 at 13:41, Gottlob Frege wrote:
>> > The easiest solution would be to store the slot as a shared_ptr, and
>> > make a copy of it (pin it) each time you call the slot.
>> So
>> Thread 1: call signal,... copy slot shared_ptr,...
>> Thread 2: disconnect, clean up resources, set global ptrUsedBySlot =
>> null (since it is no longer used, right?)
>> Thread 1: call slot
>> Thread 1: crash on null ptrUsedBySlot
> shared_ptr provides some atomic_exchange overloads. You could
> atomically swap a slot being deleted with an empty but valid slot
> type which calls nothing.

That would work to track the "winner". But if the disconnect thread
comes in second, it still needs to wait for the slot thread to finish.
So you still need a waitable synchronization object of some kind.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at