Semaphore

    [운영체제] POSIX 동기화

    POSIX는 동기화 도구로 다음 3가지를 제공한다. 1 ) mutext lock #include // mutex를 사용하기 위함. pthread_mutex_t mutex; // pthread_mutex_t 데이터형 사용. pthread_mutex_init(&mutex, NULL); pthread_mutex_lock(&mutex); pthread_mutex_unlock(&mutex); 2 ) semaphore #include // 세마포 사용을 위함. // 이름이 있는 세마포 sem_t *sem; // sem_t 데이터 형 사용 sem = sem_open("SEM", O_CREAT, 0666, 1); // 이름이 없는 세마포 sem_t sem sem_init(&sem, 0, 1) // 2번 인자 -> 0 ..