#include <pthread.h>
pthread_mutex_t mutex; // global declaration
pthread_mutex_init(&mutex, NULL); // call before first lock
/* or */
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock(&mutex); // wait
/* critical section */
pthread_mutex_unlock(&mutex); // signal
#include <semaphore.h>
sem_t sem; → no pointer // global declaration
sem_init(&sem, 0, 1); // third parameter : # of ticket
sem_wait(&sem); // acquire the semaphore
/* critical section */
sem_post(&sem); // release the semaphore
sem_t *sem; // global declaration
sem = sem_open("SEM", O_CREAT, 0666, 1);
sem_wait(sem); // acquire the semaphore
/* critical section */
sem_post(sem); // release the semaphore