boostorg / boostorg/process

POSIX multi-thread parallel childs invoked with piped std_in often do not receive STDIN close

Open
#169 13 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
145
Forks
151
PR merge metrics
No merged PRs in 30d

Description

For example this parallel POSIX child invoke with std_in from pipe often hangs on requestProcess->wait(), because child never receives STDIN close:
```
#include
#include
#include
#include

using namespace std;
namespace bp = boost::process;

void runProcess()
{
bp::opstream inputStream;
bp::ipstream outputStream;
inputStream << "test" << endl;

unique_ptr requestProcess(new bp::child("\"cat\"", bp::shell,
bp::std_in < inputStream,
(bp::std_out & bp::std_err) > outputStream));
inputStream.pipe().close();
requestProcess->wait();

std::string line;
while (outputStream && std::getline(outputStream, line) && !line.empty())
cerr << line << std::endl;
}

int main()
{
std::thread thread1(runProcess);
std::thread thread2(runProcess);
thread1.join();
thread2.join();
}
```
Note, that:
- same program does not hang on Windows ("cat" has to be replaced with "more" then)
- same program does not hang when std_in is read from file (using bp::std_in < "some_file_name.txt")
- for me it usually does not hang under debugger but hangs 100% of tries while running without debugger

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.