#include<stdio.h> #include <semaphore.h> sem_t semA, semB; main() { sem_init(&semA, 0, 0); sem_init(&semB, 0, 0); int a=0,b=0; while(1) { a++; printf("Run aaa %d\n",a); sem_post(&semB); sem_wait(&semA); printf("go to bb %d\n",a); sleep(1); } while(1) { b++; printf("post to bbb %d\n",b); sem_post(&semA); sem_wait(&semB); printf("go to aaa %d\n",b); sleep(1); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)