Boost logo

Boost :

From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2008-03-17 09:29:54

Phil Endecott <spam_from_boost_dev <at>> writes:

> I notice that Anthony Williams used the term "lockable concept" in the
> Boost.Threads release notes that he posted here recently. Anthony,
> would it be possible to say e.g. "mutex concept" in your context so
> that we can keep the term "lockable" available for something like
> this? (Or maybe they are actually the same thing. Hmmm.)

I've used the concept "lockable" to describe something which can be locked. I
felt this was a better term than "mutex", since some of the things that can be
locked are not mutexes. For example unique_lock<some_mutex> also models
"Lockable", so you can have a unique_lock<unique_lock<some_mutex> >. Hopefully
the new boost.thread docs will give you a better idea.

I would not describe a pair of data+mutex as "lockable" unless you could indeed
lock it and unlock it (with lock()/unlock() member functions). However, even if
you could, the term "lockable" wouldn't (in my view) describe what the combined
data structure was. Would "protected" better describe the intent? I know it's a
keyword, but surely the idea is to protect the data from concurrent access.

> Something else to consider is the interaction with atomic operations
> and lock-free data structures. It would be great if Locked<int> and
> Atomic<int>, or Locked<list<int>> and lockfree_list<int>, had very
> similar interfaces.

The C++0x atomic<> template will work with any type that is "trivially copy
assignable and bitwise equality comparable", and it is intended that operations
are protected with a mutex where they cannot be done with atomic ops. The
is_lock_free() member distinguishes the two cases. I would expect this to cover
many uses, though obviously you can't write atomic<list<int>>, since list<> is
definitely not bitwise equality-comparable.

How about synchronized<> to pinch a term from Java?


Anthony Williams
Just Software Solutions Ltd -
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

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