ChinaUnix.net
相关文章推荐:

pthread_cond_signal

调用pthread_cond_signal的时候最好不要pthread_mutex_lock保护, SUSv2标准是这样说的 "The pthread_cond_signal() or pthread_cond_broadcast() functions may be called by a thread whether or not it currently owns the mutex that threads calling pthread_cond_wait() or pthread_cond_timedwait() have associated with the condition variable during their waits;however, if predictable scheduling behaviour is requ...

by UnixStudier - C/C++ - 2010-07-17 00:06:01 阅读(1421) 回复(1)

相关讨论

pthread_cond_signal ()会不会把比如connect这种阻塞的操作中断 (EINTR)?

by cookis - C/C++ - 2007-04-01 00:45:06 阅读(1739) 回复(3)

pthread_cond_signal()的具体位置? 我在《linux下的多线程编程》http://www.fanqiang.com/a4/b8/20010811/0905001105.html中看到: pthread_cond_signal()必须要放在pthread_mutex_lock() 和pthread_mutex_unlock() 之间, 不然有可能造成无限制的等待。我感觉这这种调用方式是对的,但为什么不这样调用就有可能造成无限制等待,还不是很清楚???? 在这个地方看到了符合这个规则的调用: http://www.ccert.edu.cn/forum/show...

by flytod - C/C++ - 2010-07-20 23:01:41 阅读(12181) 回复(8)

man pthread_cond_signal [code] The pthread_cond_signal() function shall unblock at least one of the threads that are blocked on the specified condition variable cond (if any threads are blocked on cond). [/code]

by cookis - C/C++ - 2010-07-17 12:30:49 阅读(4679) 回复(8)

在man pthread_cond_signal里面看到这样一句话: It is not safe to use the pthread_cond_signal() function in a signal handler that is invoked asynchronously. Even if it were safe, there would still be a race between the test of the Boolean pthread_cond_wait() that could not be efficiently eliminated. 看的迷迷乎乎,是不是说pthread_cond_signal不能在异步调用的信号处理程序 使用? 否则...

by GodPig - C/C++ - 2010-07-16 23:57:16 阅读(3160) 回复(2)

原贴连接在此,希望得到各位指点 http://linux.chinaunix.net/bbs/thread-1004079-1-1.html

by NewCore - C/C++ - 2008-05-22 22:49:31 阅读(2411) 回复(3)

书上一般使用pthread_cond_wait是这样用的: 条件变量V初始化,互斥量V初始化; pthread_mutex_lock(&m); while(!wait_condition) pthread_cond_wait(&v, &m); pthread_mutex_unlock(&m); 之所以要用 while(condition) pthread_cond_wait(&v, &m)这种结构,是为了防止pthread_cond_wait由于错误的pthread_cond_signal()或者收到信号而返回 我的疑问是: 什么信号能使pthread_cond_wait()返回呢?我实验了一下SIGUSR1这个...

by new_learner - C/C++ - 2010-07-17 00:20:45 阅读(9595) 回复(11)

一个线程用pthread_cond_broadcast函数向其他线程发送信号 当程序运行一段时间以后 调用pthread_cond_broadcast函数的线程CPU占用率达100% 其他线程都停掉了 希望有知道的给解释一下 有没有什么函数可替换

by hong106525654 - C/C++ - 2006-10-09 14:12:07 阅读(1233) 回复(0)

//n 个线程 pthread_mutex_lock(&(pool->queue_lock); if (!pool->Cur_queue_size ) { pthread_cond_wait (&(pool->queue_ready), &(pool->queue_lock)); } //一些操作后 pthread_mutex_unlock(&(pool->queue_lock)); 另外一个线程 while(1) { if (pthread_mutex_trylock (&(pool->queue_lock)) == 0) { //一些操作后 pthread_mutex_unlock (&(pool->queue_lock)); pthread_cond_signal (&(pool->queue_ready)); brea...

by liujq110 - C/C++ - 2009-04-09 23:39:19 阅读(1281) 回复(1)

不能unlock 类型为pthread_MUTEX_RECURSIVE的mutex.:em08:

by 太平绅士 - C/C++ - 2009-02-06 04:13:23 阅读(1632) 回复(8)

pthread_timestruc_t to; pthread_mutex_t m; pthread_cond_t c; ... pthread_mutex_lock(&m); to.tv_sec = time(NULL) + 2; to.tv_nsec = 0; while (cond == FALSE) { err = pthread_cond_timedwait(&c, &m, &to); if (err == ETIMEDOUT) { //一直都是ETIMEDOUT,何解? /* timeout, do something */ break; } } pthread_mutex_unlock(&m); 我已经signal了,还是返回timedout。signal后,用 pthread_c...

by coolhome - C/C++ - 2008-03-21 20:34:40 阅读(4838) 回复(1)