由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - waiting for N condition variables in linux
相关主题
c++问题question about the read/write locker
condional variable thread sync 问题 (转载)is pthread_mutex_destroy() required to call?
多线程的程序设计有什么好书推荐? (转载)how to statically initialze a mutex in class?
Pthread support on Windows XPhow many ways in C++ to release a mutex?
EBUSY 的定义How to avoid deadlock ?
mutex一问请教pthread producer-consumer问题
pthread in cygwinpthread_create inside a constructor
double-checked locking你们都检查这些system call的返回值吗?
相关话题的讨论汇总
话题: condition话题: sender话题: variables话题: linux话题: waiting
进入Programming版参与讨论
1 (共1页)
j******n
发帖数: 271
1
Does anyone know if there is a Linux API allowing a single call to
block and wait for multiple condition variables, in a way similar to
select() waiting on multiple fds, and, similar to the Win32 API
WaitForMultipleObjects()? Many thanks!
X****r
发帖数: 3557
2
You can wait for a single condition and allow multiple sources signal
this condition.

【在 j******n 的大作中提到】
: Does anyone know if there is a Linux API allowing a single call to
: block and wait for multiple condition variables, in a way similar to
: select() waiting on multiple fds, and, similar to the Win32 API
: WaitForMultipleObjects()? Many thanks!

P********e
发帖数: 2610
3
除非能知道是谁signal的,否则好像不太一样

【在 X****r 的大作中提到】
: You can wait for a single condition and allow multiple sources signal
: this condition.

X****r
发帖数: 3557
4
pthread系列的wait/signal本身不传递数据,所以你反正也要用共享的变量,
加一个谁signal的变量不就行了。

【在 P********e 的大作中提到】
: 除非能知道是谁signal的,否则好像不太一样
j******n
发帖数: 271
5
That seems to have a problem. When the thread wakes up from the wait and
checks the variable identifying the sender of signal, it still cannot be
sure
that no other senders also signals the condition. As a result, it has to
check
all possible sources. One example is:
consumer waits on a condition;
sender 1 signals the condition and marks the sender id as 1;
consumer wakes up but preempted before doing anything
sender 2 signals the condition and marks the sender id as 2;
consumer continues and ch

【在 X****r 的大作中提到】
: pthread系列的wait/signal本身不传递数据,所以你反正也要用共享的变量,
: 加一个谁signal的变量不就行了。

t****t
发帖数: 6806
6
if multiple src are allowed to signal simutaneously, the "variable" must
allow this, of course.

【在 j******n 的大作中提到】
: That seems to have a problem. When the thread wakes up from the wait and
: checks the variable identifying the sender of signal, it still cannot be
: sure
: that no other senders also signals the condition. As a result, it has to
: check
: all possible sources. One example is:
: consumer waits on a condition;
: sender 1 signals the condition and marks the sender id as 1;
: consumer wakes up but preempted before doing anything
: sender 2 signals the condition and marks the sender id as 2;

X****r
发帖数: 3557
7
It is not a problem, because pthread_cont_wait automatically locks
the mutex before it returns. As long as you always access the variable
after obtained the mutex -- you must do it to make sure the wait
performs correctly anyway -- there is not problem.

【在 j******n 的大作中提到】
: That seems to have a problem. When the thread wakes up from the wait and
: checks the variable identifying the sender of signal, it still cannot be
: sure
: that no other senders also signals the condition. As a result, it has to
: check
: all possible sources. One example is:
: consumer waits on a condition;
: sender 1 signals the condition and marks the sender id as 1;
: consumer wakes up but preempted before doing anything
: sender 2 signals the condition and marks the sender id as 2;

j******n
发帖数: 271
8
The problem is not about locking the variable or not. It is about you cannot
reliably detect *ALL* senders using a simple variable to identify the sender
.
One can use a struct such as a list to store the sender ids. Then there is
the
problem that when the consumer is too slow, the list may grow unbounded.

【在 X****r 的大作中提到】
: It is not a problem, because pthread_cont_wait automatically locks
: the mutex before it returns. As long as you always access the variable
: after obtained the mutex -- you must do it to make sure the wait
: performs correctly anyway -- there is not problem.

t****t
发帖数: 6806
9
the send id should be something like a bit map, such as the one used in
select(2). no one will use a list to describe that.

cannot
sender

【在 j******n 的大作中提到】
: The problem is not about locking the variable or not. It is about you cannot
: reliably detect *ALL* senders using a simple variable to identify the sender
: .
: One can use a struct such as a list to store the sender ids. Then there is
: the
: problem that when the consumer is too slow, the list may grow unbounded.

1 (共1页)
进入Programming版参与讨论
相关主题
你们都检查这些system call的返回值吗?EBUSY 的定义
连续release mutex/semphore 2次有什么问题吗?mutex一问
pthread mutex能不能用与thread和process之间pthread in cygwin
怎么练习C++ multi-threading?double-checked locking
c++问题question about the read/write locker
condional variable thread sync 问题 (转载)is pthread_mutex_destroy() required to call?
多线程的程序设计有什么好书推荐? (转载)how to statically initialze a mutex in class?
Pthread support on Windows XPhow many ways in C++ to release a mutex?
相关话题的讨论汇总
话题: condition话题: sender话题: variables话题: linux话题: waiting