Closed lordadamson closed 5 years ago
Hey! Thanks for reporting the issue. Also, Merry Christmas!! I will take a look at it and get back to you.
Merry Christmas to you too :smile:
I tried reproducing this with std::thread instead of Open MP:
void test_multithreaded_exec()
{
auto thread_fn = []() {
auto p = sp::Popen({"cat", "-"}, sp::input{sp::PIPE}, sp::output{sp::PIPE});
auto msg = "through stdin to stdout";
auto res_buf = p.communicate(msg, strlen(msg)).first;
assert(res_buf.length == strlen(msg));
};
std::vector<std::thread> threads;
for (int i = 0; i < 100; i++) {
threads.emplace_back(std::thread{thread_fn});
}
for (int i=0; i < 100; i++) {
threads[i].join();
}
std::cout << "END_TEST" << std::endl;
}
Popen object if used within a thread context should be thread safe. Is there any Open MP specific thing going on here ?
Hi @arun11299 I failed to reproduce the issue on an MCVE. That suggests that there is a memory corruption happening somewhere else in my code that's causing the issue.
Thanks a lot for looking into this. I'll investigate further and will let you know if I have any useful findings.
Sure. Let me know.
Or does it provide the option of thread safety?
In my code I'm using an openmp loop where I would like to call
sp::Popen
.It looks something like this:
where v is a
std::vector<std::string>
but it hangs randomly at thefork()
call in subprocess.hpp:1159Thanks in advance and thanks for the amazing library.