|
Boost : |
From: Matthew Hurd (matthurd_at_[hidden])
Date: 2000-05-31 12:02:21
Hi,
<...>
> The #define is what I use for MT/None-MT. If it isn't defined all
> my MT stuff expands into empty inline functions which the optimizer
> should take care of.
> I don't think clients who don't need thread safety should pay for it.
<...>
> Schobi
I like #define too.
A mixed approach would be for the #define to optionally select a MT strategy
or a NULL_MT strategy, such as the ACE's Null_Mutex below, for code
explicitly abstracted for MT.
I've pasted a reference to the ACE's OO concurrency approach below. It's a
little old, I'm not sure how much things have changed since then (1995?).
Bjarne Stroustrup gave a talk (technetcast from somewhere) where he
mentioned he was going to publish an article regarding a neatly transparent
concurrency idea. From memory, he was overloading operator-> to lock on use
and the object returned from the operator-> would unlock. Has anyone a
reference to this?
Having MT mechanisms is half the battle. The other half is applying it to
Container< T > or whatever. I think there are three modes (ignoring RW):
(1) Lock, use lots of methods, unlock
(2) Method locks and unlocks if necessary
(3) Access to method locks and unlocks if necessary
cheers,
matt.
Extract from "An OO Encapsulation of Lightweight OS Concurrency Mechanisms
in the ACE Toolkit" at
http://www.cs.wustl.edu/~schmidt/ACE-concurrency.ps.gz
"
5.1.5 The Null Mutex Class
The Null Mutex class provides a zero-overhead implementation
of the general locking interface shared by the other C++ wrappers for
threading and synchronization. The interface and trivial implementation for
Null Mutex is shown below:
class Null_Mutex
{
public:
Null_Mutex (void) {}
~Null_Mutex (void) {}
int remove (void) { return 0; }
int acquire (void) const { return 0; }
int try_acquire (void) const { return 0; }
int release (void) const { return 0; }
};
As shown in the code above, the Null Mutex class implements
the acquire and release methods as "no-op"
inline functions that are removed completely by a compiler
optimizer. Section 6 illustrates the use of the Null Mutex.
"
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk