pthread_cond_signal 질문

익명 사용자의 이미지

안녕하세요

pthread_cond_signal은 다른 쓰레드에서 pthread_cond_wait (같은 조건변수를 가지는 경우)로 대기상태인 곳을 넘어가게 하는 역할이라고 알고 있습니다.

여기서 궁금한 사항은.

원하던 동작은 thread1에서 wait에서 대기하고있다가 thread2의 signal을 받는 것인데,
thread1의 wait대기상태로 오기 전에 thread2에서 signal이 불려지면 어떻게 되는 건가요?

기다리고 있는 wait가 없을경우 signal은 그냥 불려지기만 하고 아무동작 안하고 넘어가는 걸까요?

익명 사용자의 이미지

네, 아무 동작 안하고 넘어갑니다.

https://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_cond_signal.html

Quote:
The pthread_cond_signal() call unblocks at least one of the threads that are blocked on the specified condition variable cond (if any threads are blocked on cond).

...

The pthread_cond_signal() and pthread_cond_broadcast() functions have no effect if there are no threads currently blocked on cond.