[lldb/test] Fix data racing issue in TestStackCoreScriptedProcess
authorMed Ismail Bennani <medismail.bennani@gmail.com>
Wed, 11 Jan 2023 00:28:25 +0000 (16:28 -0800)
committerMed Ismail Bennani <medismail.bennani@gmail.com>
Fri, 13 Jan 2023 03:20:51 +0000 (19:20 -0800)
commit8f549c5329275293ced1d5eb87a1cf8b3d52a794
treecadf4424fc5af20033bfe1f5b2c313b479f3aca8
parente3930e77fc5b626a3c6b95f08ed25a3f8807c579
[lldb/test] Fix data racing issue in TestStackCoreScriptedProcess

This patch should fix an nondeterministic error in TestStackCoreScriptedProcess.

In order to test both the multithreading capability and shared library
loading in Scripted Processes, the test would create multiple threads
that would take the same variable as a reference.

The first thread would alter the value and the second thread would
monitor the value until it gets altered. This assumed a certain ordering
regarding the `std::thread` spawning, however the ordering was not
always guaranteed at runtime.

To fix that, the test now makes use of a `std::condition_variable`
shared between the each thread. On the former, it will notify the other
thread when the variable gets initialized or updated and on the latter,
it will wait until the variable it receives a new notification.

This should fix the data racing issue while preserving the testing
coverage.

rdar://98678134

Differential Revision: https://reviews.llvm.org/D139484

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
lldb/test/API/functionalities/scripted_process/Makefile
lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
lldb/test/API/functionalities/scripted_process/baz.c [deleted file]
lldb/test/API/functionalities/scripted_process/baz.cpp [new file with mode: 0644]
lldb/test/API/functionalities/scripted_process/baz.h
lldb/test/API/functionalities/scripted_process/main.cpp