#include #include #include pthread_mutex_t our_mutex = PTHREAD_MUTEX_INITIALIZER; void* thread_function(void* input){ puts("Thread: Starting the thread and acquiring the lock"); pthread_mutex_lock(&our_mutex); puts("Thread: We've got the lock now!"); sleep(1); pthread_mutex_unlock(&our_mutex); puts("We've released the lock and are finished"); } void main(){ pthread_mutex_lock(&our_mutex); pthread_t t; pthread_create(&t, 0, thread_function, 0); puts("Thread is created, but the lock is held by main right now"); sleep(5); puts("About to release the lock"); pthread_mutex_unlock(&our_mutex); pthread_join(t, 0); }