mirror of
https://github.com/intel/llvm.git
synced 2026-01-28 01:04:49 +08:00
As the documentation states, using this is not safe in multithreaded
programs, and I have traced it to a rare deadlock in some of the tests.
The reason this was introduced was to be able to attach to a program
from the very first instruction, where our usual mechanism of
synchronization -- waiting for a file to appear -- does not work.
However, this is only needed for a single test
(TestGdbRemoteAttachWait) so instead of doing this everywhere, I create
a bespoke solution for that single test. The solution basically
consists of outsourcing the preexec_fn code to a separate (and
single-threaded) shim process, which enables attaching and then executes
the real program.
This pattern could be generalized in case we needed to use it for other
tests, but I suspect that we will not be having many tests like this.
This effectively reverts commit
a997a1d7fb.
9 lines
128 B
C++
9 lines
128 B
C++
#include <thread>
|
|
|
|
int main()
|
|
{
|
|
// Wait to be attached.
|
|
std::this_thread::sleep_for(std::chrono::minutes(1));
|
|
return 0;
|
|
}
|