[test] Fix data race in samples/ffi/async/async_test.

TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/55615
Change-Id: I4de5701037640f5b0ae6b176f695907c4c5e1ef5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365209
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
This commit is contained in:
Ryan Macnak 2024-05-02 06:44:29 +00:00 committed by Commit Queue
parent 25a309a85c
commit ed5aeab889

View file

@ -480,9 +480,10 @@ intptr_t MyCallbackBlocking(intptr_t a) {
auto callback = my_callback_blocking_fp_; // Define storage duration.
std::condition_variable cv;
bool notified = false;
const Work work = [a, &result, callback, &cv, &notified]() {
const Work work = [a, &result, callback, &mutex, &cv, &notified]() {
result = callback(a);
printf("C Da: Notify result ready.\n");
std::unique_lock<std::mutex> lock(mutex);
notified = true;
cv.notify_one();
};