pthread_mutex_t my_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&my_mutex); /* locked code */ pthread_mutex_unlock(&my_mutex);