//我理解的四种消息:c打球成功,c打球失败;j打球成功,j打球失败
sem_t t1,t2,t3,t4;
sem_init(&t1,0);
sem_init(&t2,0);
sem_init(&tc,1);//初始化时c打球
sem_init(&tj,0);
int score_c=0;
int score_j=0;
control(){//c打球失败时,j计分
sem_wait(&t1);
score_j++;
sem_post(&tj);
}
control2(){
sem_wait(&t2);
score_c++;
sem_post(&tc);
}
fc(){
sem_wait(&tc);
if(发球失败){
sem_post(&t1);
}
else{
sem_post(&tj);
}
}
fj(){
sem_wait(&tj);
if(发球失败){
sem_post(&t2);
}
else{
sem_post(&tc);
}
}