#ifndef LOCK_H_ #define LOCK_H_ #include // has pthread_ routines // ---- Class for lock ----------------------------------------------- // By defining a class for locks, we ensure that pthread_mutex_init // and pthread_mutex_destroy are called automagically (respectively, // when a lockObj is declared and goes out of scope). class lockObj { public: // Constructor (no arguments) and destructor. lockObj(void) { pthread_mutex_init(&theLock, NULL); } ~lockObj(void) { pthread_mutex_destroy(&theLock); } private: // Copy constructor and assignment operator: Make private so // they can't be used (and we don't have to write them). lockObj(const lockObj & d); lockObj & operator= (const lockObj & d); public: // Function to acquire the lock. void lock(void) { pthread_mutex_lock(&theLock); } // Function to release the lock. void unlock(void) { pthread_mutex_unlock(&theLock); } private: // member variables pthread_mutex_t theLock; }; #endif // LOCK_H_