Boost logo

Boost :

Subject: Re: [boost] [thread] synchronized_value: value and move semantics
From: Vicente Botet (vicente.botet_at_[hidden])
Date: 2013-06-26 11:55:33


Andrey Semashev-2 wrote
> On Wed, Feb 20, 2013 at 10:02 PM, Vicente J. Botet Escriba <

> vicente.botet@

>> 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 missed this discussion somehow. I've taken a quick look at the
> interface and have a few questions:
>
> 1. Why are there strict_lock_ptr and unique_lock_ptr?

These a locking pointers that lock at construction and unlock at
destruction. Both classes have pointer semantics.

> What are the
> differences

strict_lock_ptr cannot be unlocked (something like lock_guard) and
unique_lock_ptr is a model of Lockable so it provides the lock/unlock
functions as unique_lock.

> and why we can't have one such ptr (presumably,
> unique_lock_ptr)?

Sorry I don't understand.

> 2. I find value() and get() a bit confusing, since it is not apparent what
> is the difference between them. Maybe value() could be renamed to
> get_ref()
> or unsafe_get()?

You are right the names are not clear.

get() is a explicit conversion.

value() return a const reference.

> 3. Am I correct that having strict_lock_ptr/unique_lock_ptr acquired by
> calling synchronize() will not deadlock with operator-> when a
> non-recursive mutex is used?

To which operator-> are you referring to? the one from
strict_lock_ptr/unique_lock_ptr?
synchronize() is used to lock at block scope. The user must use the obtained
locking pointer to access to the functions of the synchronized value using
the operator->.
I'm not sure to understand what could be the issue.

best,
Vicente

--
View this message in context: http://boost.2283326.n4.nabble.com/thread-synchronized-value-value-and-move-semantics-tp4643126p4648962.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

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