confide

导航

2011年8月10日 #

unix编程——互斥锁

摘要: 互斥锁用于保护临界区,保证任何时刻只有一个线程或进程执行其中的代码,临界区是一次只能允许一个线程或进程使用的共享资源。生产者和消费者问题代码如下:View Code #include <stdlib.h>#include <stdio.h>#include <pthread.h>int nitems;pthread_mutex_t imux;int curp;void*producer(){ while(1){ pthread_mutex_lock(&imux); curp++; if(curp>nitems){ pthread_mutex_u 阅读全文

posted @ 2011-08-10 10:32 confide 阅读(335) 评论(0) 推荐(0)