int main()
{
printf("多线程,写者优先\n");
pthread_mutex_init(&mutex_write,NULL);
pthread_mutex_init(&mutex_read,NULL);
sem_init(&sem_write,0,1);
sem_init(&sem_read,0,1);
int i = 0;
for(i = 0; i < N_READER; i++)
{
pthread_create(&rid[i],NULL,reader,NULL);
}
for(i = 0; i < N_WRITER; i++)
{
pthread_create(&wid[i],NULL,writer,NULL);
}
sleep(1);
return 0;
}
写者优先