Windows中的WaitForSingleObject()函数对应在Linux中的sem_wait(),SetEvent对应sem_post(),
Windows中的WaitForSingleObject()函数对应在vxworks中semTake(),SetEvent对应semGive().
参考下面的Linux程序:
-
char tem[10];
-
sem_t sem;
-
void* thread_fun(void*);
-
int main()
-
{
-
int counter=0;
-
pthread_t mythread;
-
sem_init(&sem,0,0);
-
pthread_create(&mythread,NULL,thread_fun,NULL);
-
while(counter<10)
-
{
-
tem[counter]='f';
-
counter++;
-
sem_post(&sem);
-
}
-
pthread_join(mythread,NULL);
-
sem_destroy(&sem);
-
exit(0);
-
}
-
void* thread_fun(void* arg)
-
{
-
int counter=0;
-
while(counter<10&&sem_wait(&sem)==0)
-
{
-
printf("%c",tem[counter]);
-
counter++;
-
-
}
-
pthread_exit(NULL);
-
}
阅读(2464) | 评论(0) | 转发(0) |