• linux中进程问题

    #include <stdio.h> #include<string.h> #include <semaphore.h> #include <pthread.h> #include <windows.h> #include <unistd.h> sem_t empty; //定义信号量 sem_t applefull; sem_t orangefull; void *procf(void *arg) //father线程 { while(1){ sem_wait(&empty;); //P操作 printf("%s\n",(char *)arg); sem_post(&applefull;); //V操作 Sleep(7); } } void *procm(void *arg) //mother线程 { while(1){ sem_wait(&empty;); printf("%s\n",(char *)arg); sem_post(&orangefull;); Sleep(3); } } void *procs(void *arg) //son线程 { while(1){ sem_wait(&orangefull;); printf("%s\n",(char *)arg); sem_post(&empty;);sleep(2); } } void *procd(void *arg) //daughter线程 { while(1){ sem_wait(&applefull;); printf("%s\n",(char *)arg); sem_post(&empty;);sleep(5); } } main() { pthread_t father; //定义线程 pthread_t mother; pthread_t son; pthread_t daughter; sem_init(&empty;, 0, 1); //信号量初始化 sem_init(&applefull;, 0, 0);

    0
    196
    2KB
    2013-01-06
    18
  • 分享学徒

    成功上传1个资源即可获取
关注 私信
上传资源赚积分or赚钱