boostorg / boostorg/process

POSIX wait_for() crashes when multiple threads run it simultaneously

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

Description

Seems POSIX wait_for() is not thread-safe. Following simple program crashes:

```
#include
#include

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

void runProcess()
{
unique_ptr requestProcess(new bp::child("\"echo test\"", bp::shell));
while (requestProcess->running())
requestProcess->wait_for(chrono::seconds(1));
}

int main()
{
std::thread thread1(runProcess);
std::thread thread2(runProcess);
thread1.join();
thread2.join();
}
```
With stacktrace:
```
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000559ed51d75b3 in boost::process::detail::posix::wait_until > >(boost::process::detail::posix::child_handle const&, int&, std::chrono::time_point > > const&, std::error_code&)::signal_interceptor_t::handler_func(int) (
val=17127) at ../../boost_1_74_0-native/include/boost/process/detail/posix/wait_for_exit.hpp:69
#1 0x0000559ed51d75b5 in boost::process::detail::posix::wait_until > >(boost::process::detail::posix::child_handle const&, int&, std::chrono::time_point > > const&, std::error_code&)::signal_interceptor_t::handler_func(int) (
val=17127) at ../../boost_1_74_0-native/include/boost/process/detail/posix/wait_for_exit.hpp:69
...
```

Notes:
- same code with requestProcess->wait() does not crash
- same code works on older Boost::Process (like with version 1.67)

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.