|
|
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 Mutex ()
| Mutex |
constructor
| ~Mutex ()
| ~Mutex |
[virtual]
destructor
| inline void lock ()
| lock |
locks the mutex
| inline void unlock ()
| unlock |
unlocks the mutex
| Generated by: stefan on stefan on Sat Jun 2 23:13:28 2001, using kdoc 2.0a53. |