http://blog.youkuaiyun.com/tenfyguo/article/details/5274435
http://blog.youkuaiyun.com/tenfyguo/article/details/5274396
如何判断工作线程都初始化完毕:
在dispatcher线程里:
- pthread_mutex_lock(&init_lock);
- while (init_count < nthreads) {
- pthread_cond_wait(&init_cond, &init_lock);
- }
- pthread_mutex_unlock(&init_lock);
在worker线程里:
- pthread_mutex_lock(&init_lock);
- init_count++;
- pthread_cond_signal(&init_cond);
- pthread_mutex_unlock(&init_lock);
wait和signal一一对应,因为只有一个dispatcher线程的wait,所以可以准确判断worker线程是否都初始化完毕。