I am writing an application which blocks on input from two istreams
.
Reading from either istream
is a synchronous (blocking) call, so, I decided to create two Boost::thread
s to do the reading.
Either one of these threads can get to the "end" (based on some input received), and once the "end" is reached, both input streams stop receiving. Unfortunately, I cannot know which will do so.
Thus, I cannot join()
on both threads, because only one thread (cannot be predetermined which one) will actually return (unblock).
I must somehow force the other to exit, but it is blocked waiting for input, so it cannot itself decide it is time to return (condition variables or what not).
Is their a way to either:
- Send a signal a boost::thread, or
- Force an
istream
to "fail", or - Kill a Boost::thread?
Note:
- One of the
istreams
iscin
- I am trying to restart the process, so I cannot close the input streams in a way that prohibits reseting them.
Edit:
- I do know when the "end" is reached, and I do know which thread has successfully finished, and which needs to be killed. Its the killing I need to figure out (or a different strategy for reading from an istream).
- I need both threads to exit and cleanup properly :(
Thanks!