세마포로 3개의 쓰레드안에 있는 내용을 순서대로 출력하기에 대한 질문이요
글쓴이: dream2come / 작성시간: 화, 2009/05/05 - 9:40오후
제목 그래로 수행하는건데 다 찾아봤는데 도저히 안되서
여기에 올려봅니다
코드도 올리니 한번 봐주세요
생각한거는 처음에 first는 1로 나머지는 0으로 줘서
first,second 등으로 printf() 다음 post로 1증가 시키고 그다음 세마포의 wait를 풀어서 실행 또 그다음 실행......이런건데
안되네요
#include <semaphore.h>
sem_t* first;
sem_t* second;
sem_t* third;
sem_t* fourth;
void *lect ()
{
sema_wait(&second);
printf("hey");
sema_post(&third);
pthread_exit(0);
}
void *lect2 ()
{
sema_wait(&third);
printf(" ");
sema_post(&fourth);
pthread_exit(0);
}
void *lect()
{
sema_wait(&first);
printf("\"");
sema_post(&second);
sema_wait(&fourth);
printf(",");
pthread_exit(0);
}
int main ()
{
sema_init(&first,1,NULL,NULL);
sema_init(&second,0,NULL,NULL);
sema_init(&third,0,NULL,NULL);
sema_init(&fourth,0,NULL,NULL);
--> 나머지는 pthread_ctread,join,sema_destroy 입니다.
}
그리고 하나의 thread안에 세마포 여러개 사용하면 안되나요
실행이 안되던데...
Forums:


댓글 달기