동기화

    [운영체제/OS] POSIX Semaphore 동기화

    POSIX Semaphore -Named semaphore 여러 프로세스에서 공유할 수 있다. #include sem_t *sem; /*create the semaphore and initialize it to 1*/ sem = sem_open("SEM", O_CREAT, 0666, 1); /*acquire the semaphore*/ sem_wait(sem); /*critical section*/ /*release the semaphore*/ sem_post(sem); -Unnamed semaphore #include sem_t sem; /*create the semaphore and initialize it to 1*/ sem_init(&sem, 0, 1); /*acquire the semaphore..

    [운영체제/OS] Synchronization_동기화, 임계 구역 문제

    동기화(Synchronization) Producer (=master): 데이터 생성 while(TRUE) { //produce an item and put into the buffer while(counter==BUFFER_SIZE) //is buffer full? ; //do nothing //busy waiting. spin lock buffer[in] = nextProduced;//write연산 (차있지 x경우) in = (in+1) % BUFFER_SIZE; counter++; } Consumer while(TRUE) { while(counter == 0) //is buffer empty? ; //do nothing nextConsumed = buffer[out]; out = (out+1) % ..