
19 Apr
2006
19 Apr
'06
1:36 a.m.
On 4/18/06, me22
As usual when you want fancy scope control, you can use a pointer. One of the smart pointers to the lock would work nicely.
Or how about making a smart pointer itself manage the lock? I especially like Alexendrescu's LockingPtr, but rather than go with his OOTB implementation, factor out the mutex into a wrapper class so you end up with class implementors not caring about multi-threadedness and clients explicitly choosing whether or not they want thread safety. For example, something like: Lockable< MyClass > myClass; LockingPtr< MyClass > myClassPtr( myClass ); Noel