I am developing a Windows application that has a separate thread for processing a user (or third-party) application through stdin.
This thread is designed in such a way that it waits through WaitForMultipleObjects two events:
- Signal of death . When this signal rises, the interface processing flow is turned off.
- Interface signal . When this signal is raised, the input is ready to read. The input is read and processed.
On Windows, this thread enters the main loop, where Wait for these two events (where bWaitAll is FALSE ). Waiting for the stdin descriptor has a signaling effect when there is a read-in input, and another event is set elsewhere in the application.
It works exactly the way I want. He expects the event to be raised without entering a lively expectation, and he will expect both events at the same time.
I want to port this functionality to Linux, but I'm not sure how to achieve the desired result. Essentially, I really want:
On Linux, how do I create a thread so that it responds immediately to user input on stdin, but it can also respond immediately so that the death flag is raised from another location in the application?
To accomplish the latter, it seems to me that I cannot use cin , gets , getch or any other function that blocks until the user enters text. However, I do not know how to read user input in a console application without blocking.
I am open to any changes in architecture (if there are more features for Linux-y), which include entering user input into a separate stream, which can be removed from another place in the application. I am using GCC 4.4 and Boost 1.51.
source share