Boost logo

Boost :

Subject: Re: [boost] [thread] synchronized_value: value and move semantics
From: Ben Pope (benpope81_at_[hidden])
Date: 2013-06-26 06:37:32

On 21/02/13 02:02, Vicente J. Botet Escriba wrote:
> Hi,
> boost::synchronized_value (not released yet [1][2][3]) is based on [4].
> See below part of this paper adapted to the Boost.Thread interface.
> Currently boost::synchronized_value is in addition Copyable and
> Swappable. I was wondering if it is worth adding value and move
> semantics to synchronized_value. Making it EqualityComparable,
> LessThanComparable and Movable if the underlying type satisfy these
> requirements will allow to store them on a Boost.Container/C++11 container.
> Do you see something completely wrong with this addition?
> Has some of you had a need for this? Could you share the context?

Sorry, I'm a bit late to the party and not really answering the question.

I can see the usefulness of synchronized_value for C++03, but not in C++11.

It's just too easy to forget to call the synchronise() member:

boost::synchronized_value<std::queue<int>> synch_queue;

when was was meant was (excuse use of auto, I've become lazy):

boost::synchronized_value<std::queue<int>> synch_queue;
    auto lock = synch_queue.synchronize();

This is neither safe or efficient (2 lock/unlocks).

I think this should just not exist in C++11 and instead be replaced by
something like monitor<T> described by Herb Sutter [1]:

monitor<std::queue<int>> synch_queue;
queue([](std::queue& q)

Now we're safe and efficient (one lock/unlock per block).

Since movability is a C++11 thing, can we have something harder to use
incorrectly than synchronized_value for C++11?

I guess my point is rather than C++11ifying synchronized_value, can we
have monitor instead?



 From 0:40:00

Boost list run by bdawes at, gregod at, cpdaniel at, john at