Boost logo

Boost Users :

Subject: Re: [Boost-users] Signals2 benchmark
From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2015-02-06 14:23:15


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.

You'd see some fragmentation over time, but to be honest if the slots
array fits into an L1 cache you actually don't care. My
concurrent_unordered_map keeps a linear array of hashes and pointers
to items and simply scans them. Deletion means poking a zero into the
pointer, insertion tries to fill a zero slot before bothering with
extension. It's very quick, within 20% of a std::unordered_map.

Niall

-- 
ned Productions Limited Consulting
http://www.nedproductions.biz/ 
http://ie.linkedin.com/in/nialldouglas/



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net