第八章 Linux线程.ppt

第八章 Linux线程

* * * 3-1pthread_mutex pthread_mutex_t job_queue_mutex = PTHREAD_MUTEX_INITIALIZER; void* thread_function (void* arg) { while (1) { struct job* next_job; pthread_mutex_lock (job_queue_mutex); if (job_queue == NULL) next_job = NULL; else { next_job = job_queue; job_queue = job_queue-next; } pthread_mutex_unlock (job_queue_mutex); if (next_job == NULL) break; proces_job (next_job); free (next_job); } return NULL; } 初始化互斥体 获得互斥体 释放互斥体 受保护区域 为什么不在

文档评论(0)

1亿VIP精品文档

相关文档