728x90
일반적으로 pthread_mutex_lock과 pthread_cond_wait는 다음과 같이 동작한다.
=====================
pthread_mutex_lock
if (condition)
then
pthread_cond_wait
end if
조건에 따른 내용 처리
pthread_mutex_unlock
======================
하지만, OS에 따라 pthread_cond_wait 혹은 pthread_cond_timedwait는 비정상적으로 깨어날 수 있다.
이것은 linux man page에도 Spurious wakeups라고 명시되어 있다.
이를 극복하기 위해 다음과 같이 condition check의 if 문을 while문으로 변경하면 된다.
=====================
pthread_mutex_lock
while (condition)
then
pthread_cond_wait
end while
조건에 따른 내용 처리
pthread_mutex_unlock
======================
728x90
'프로그래밍 > C언어' 카테고리의 다른 글
C언어에서 bool type 사용법 (0) | 2013.09.11 |
---|