[완료] pthread_cond_wait 가 wait 되지 않습니다.
글쓴이: ikpil / 작성시간: 목, 2010/01/07 - 2:28오후
#include <pthread.h>
#include <windows.h>
pthread_mutex_t mut;
pthread_cond_t cond;
void *f( void * )
{
pthread_cond_wait( &cond, &mut );
return 0;
}
int main(int argc, char *argv[])
{
int res = 0;
res = pthread_mutex_init(&mut, NULL);
res = pthread_cond_init(&cond, NULL);
pthread_t pt;
pthread_create(&pt, NULL, f, NULL);
void *p;
pthread_join(pt, &p );
pthread_mutex_destroy(&mut);
pthread_cond_destroy(&cond);
return 0;
}질문
pthread_cond_wait 가 wait 되지 않고, 지나가는데 무엇이 잘못 된 건가요?
1시간째 예제 돌려 보고, 다른 거 돌려봐도 wait가 안되네요.
실행 환경
windows7 kn 32bit
비쥬얼 스튜디오 2008
pthread 최신 버전
Forums:


예제를 잘못 이해
예제를 잘못 이해 했었네요.
2시간만에 이해 했습니다. 머리가 나쁩니다.
wait시 락을 걸고 wait 시켜야 했군요.
관계를 그림을 그려 생각해 봐야겠습니다.
#include <pthread.h> #include <windows.h> pthread_mutex_t mut; pthread_cond_t cond; void *f( void * ) { pthread_mutex_lock( &mut ); pthread_cond_wait( &cond, &mut ); pthread_mutex_unlock( &mut ); return 0; } int main(int argc, char *argv[]) { int res = 0; res = pthread_mutex_init(&mut, NULL); res = pthread_cond_init(&cond, NULL); pthread_t pt; pthread_create(&pt, NULL, f, NULL); Sleep(2000); pthread_cond_signal(&cond); void *p; pthread_join(pt, &p); pthread_mutex_destroy(&mut); pthread_cond_destroy(&cond); return 0; }http://www.ikpil.com
http://www.ikpil.com
...
msvc에 pthread_*() 함수가 있나요? -ㅁ-;;
댓글 달기