|
|
A mutex
To protect a critical section, you can use a mutex, which will ensure that only one thread at a time can lock it. Here is an example for a thread-safe random number generator:
class RandomGenerator {
Arts::Mutex mutex;
long seed;
public:
long get() {
mutex.lock();
// do complicated calculation with seed here
mutex.unlock();
return seed;
}
};
|
| inline |
constructor
| |
[virtual]
destructor
| inline void |
locks the mutex
| inline void |
unlocks the mutex
| Generated by: stefan@stefan on Sat Feb 24 19:11:23 2001, using kdoc 2.0a47. |