Hello List, I have a thread with a class and its method that raises a "question" signal and needs to wait with a timeout for an "answer" signal. There are several worker threads, some of which may be connected to the question signal. The answer signal will be raised by a worker thread only if it knows the answer; it is possible that no worker thread knows the answer so no answer signal will be raised (hence need for timeout). The question thread cannot know which worker thread to ask. What is a good way to achieve this using boost 1.58 and/or C++11? I am using g++ 4.9 on 64bit ubuntu 14.04. Thanks, Vic
On Thu, May 21, 2015 at 4:18 PM, Victor Yankee
Hello List,
I have a thread with a class and its method that raises a "question" signal and needs to wait with a timeout for an "answer" signal.
There are several worker threads, some of which may be connected to the question signal. The answer signal will be raised by a worker thread only if it knows the answer; it is possible that no worker thread knows the answer so no answer signal will be raised (hence need for timeout). The question thread cannot know which worker thread to ask.
Sounds like a homework question to me. Besides which, the problem statement pretty much spelled out where you likely need to focus.
What is a good way to achieve this using boost 1.58 and/or C++11? I am using g++ 4.9 on 64bit ubuntu 14.04.
Thanks, Vic
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 22/05/2015 08:18, Victor Yankee wrote:
I have a thread with a class and its method that raises a "question" signal and needs to wait with a timeout for an "answer" signal.
There are several worker threads, some of which may be connected to the question signal. The answer signal will be raised by a worker thread only if it knows the answer; it is possible that no worker thread knows the answer so no answer signal will be raised (hence need for timeout). The question thread cannot know which worker thread to ask.
The first thing you need to work out is what happens if more than one worker thread knows the answer. Or whether this is not possible for other reasons.
The root of the problem is that I wanted 2 worker threads to communicate
asynchronously via "one-way" signals and expected this:
Time Action
-------- -----------------------------------
1 Thread 1: raises signal
2 Thread 1: set up and wait for reply signal with a timeout
Thread 2: catches signal
3 Thread 2: composes and raises reply signal
4 Thread 1: catches reply
But what happens is that Thread 2 replies before Thread 1 can set up the
wait for the reply, so it times out, even though the reply was actually
sent.
What is the best way to fix this problem?
On Fri, May 22, 2015 at 12:42 AM, Gavin Lambert
On 22/05/2015 08:18, Victor Yankee wrote:
I have a thread with a class and its method that raises a "question" signal and needs to wait with a timeout for an "answer" signal.
There are several worker threads, some of which may be connected to the question signal. The answer signal will be raised by a worker thread only if it knows the answer; it is possible that no worker thread knows the answer so no answer signal will be raised (hence need for timeout). The question thread cannot know which worker thread to ask.
The first thing you need to work out is what happens if more than one worker thread knows the answer. Or whether this is not possible for other reasons.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Wed, Jun 3, 2015 at 10:37 AM, Victor Yankee
The root of the problem is that I wanted 2 worker threads to communicate asynchronously via "one-way" signals and expected this:
Time Action -------- ----------------------------------- 1 Thread 1: raises signal
2 Thread 1: set up and wait for reply signal with a timeout Thread 2: catches signal
3 Thread 2: composes and raises reply signal
4 Thread 1: catches reply
But what happens is that Thread 2 replies before Thread 1 can set up the wait for the reply, so it times out, even though the reply was actually sent.
What is the best way to fix this problem?
Are you using Boost.Signals2 (signals and slots) ? Or condition variables (condvars) ? Where is the answer written? It is a global integer (ie static int answer = 42;) or somehow sent with the signal? Do you understand "spurious wakeups" (if using condvars) ? Tony
participants (4)
-
Gavin Lambert
-
Gottlob Frege
-
Michael Powell
-
Victor Yankee