I cannot use boost or the latest std::thread library. The way to go is to create a custom implementation of a scoped mutex.
In a few words when a class instance is create a mutex locks. Upon class destruction the mutex is unlocked.
Any implementation available? I don’t want to re-invent the wheel.
I need to use pthreads.
- resource acquisition is initialization == “RAII”
Any RAII tutorial will do.
Here’s the gist: (also on http://ideone.com/kkB86)
Of course you can make it generic towards
mutex_t, you could prevent subclassing.Copying/assignment is already prohibited because of the reference field
EDIT For pthreads: