读者优先、写者优先问题(3)

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;
}

写者优先

读者优先、写者优先问题

读者优先、写者优先问题

读者优先、写者优先问题

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/e2ca80d2ce044d3161a30b12e9c096f3.html