#include Mutex::Mutex() { pthread_mutex_init( &mutex_var, NULL); locked = false; } Mutex::~Mutex() { if( locked == true) pthread_mutex_unlock( &mutex_var); pthread_mutex_destroy( &mutex_var); } // Returns 0 on success int Mutex::P(void) { locked = true; return pthread_mutex_lock( &mutex_var); } // Returns 0 on success int Mutex::V(void) { if ( locked == true ) return pthread_mutex_unlock( &mutex_var); else return -1; }