|
Boost : |
From: Rob Stewart (stewart_at_[hidden])
Date: 2004-07-23 23:00:10
From: Howard Hinnant <hinnant_at_[hidden]>
>
> I've just thought of alternative syntax. I'm not sure yet whether I
> like it or not. But I'm putting it out there so that it gets more eyes
> than just my own (which are badly overworked at the moment)...
>
> Below, allow for the pseudo code notation:
>
> scoped_lock = move(scoped_lock);
>
> To mean that given:
>
> scoped_lock<Mutex> lock1(mut, defer_lock);
> scoped_lock<Mutex> lock2(mut);
>
> you can do:
>
> lock1 = move(lock1);
lock2 = move(lock1) // ???
> We currently have (just discussing assignment forms below):
>
> scoped_lock = move(scoped_lock);
> scoped_lock = move(upgradable_lock); // 1
> scoped_lock = try_move(upgradable_lock); // 2
>
> sharable_lock = sharable_lock;
> sharable_lock = upgradable_lock;
> sharable_lock = move(scoped_lock);
>
> upgradable_lock = sharable_lock;
> upgradable_lock = move(upgradable_lock);
> upgradable_lock = move(scoped_lock);
>
> Those forms not using try_move or move take a const& on the rhs, and
> never block.
>
> Those forms using move on the rhs require the rhs to be an rvalue (or
> cast with move), and never block except for 1, which can block.
>
> The form taking try_move is a try-lock form of 1 (and thus can not
> block).
>
> Possible alternative syntax:
>
> scoped_lock = move(scoped_lock);
> scoped_lock |= move(upgradable_lock); // 1
I like the pipe's suggestion of a wall and, hence, blocking. The
x= operators are good, in general, as they still suggest
assignment (<<= is better than << for that reason).
> scoped_lock <<= move(upgradable_lock); // 2
This isn't as suggestive as the |=. How about these:
scoped_lock ~= move(upgradable_lock);
scoped_lock %= move(upgradable_lock);
The ~ in ~= sort of suggests try, as in try-lock. Unfortunately,
the tilde is small so it doesn't stand out really well.
%= is almost never overloaded, so that makes it a good candidate
for coopting for this purpose, and it sort of suggests the
wishy-washy nature of try-lock.
-- Rob Stewart stewart_at_[hidden] Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk