#include #include #include sem_t sem; int count=0; void ProvideService(){ while(1) { // Wait semaphore sem_wait(&sem); if (count<0x7fffffff) count++; else count--; // printf("count is %d\n",count); } } void SendRequest() { while(1) { sem_post(&sem); sleep(10); } } int main() { pthread_t t1,t2; sem_init(&sem,0,0); pthread_create(&t1, NULL, (void *)SendRequest, NULL); pthread_create(&t2, NULL, (void *)ProvideService, NULL); pthread_join(t2,NULL); return 1; }