pw_async2: Fix TSAN for dispatcher_thread_test

This test was mistakenly modifying non-atomic
variables without a lock and then reading from
them on another thread.

Fix: b/332687703

Change-Id: If73d045185775d6831cea99851741db806b74d8f
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/201850
Commit-Queue: Taylor Cramer <cramertj@google.com>
Pigweed-Auto-Submit: Taylor Cramer <cramertj@google.com>
Reviewed-by: Ted Pudlik <tpudlik@google.com>
This commit is contained in:
Taylor Cramer 2024-04-04 00:00:02 +00:00 committed by CQ Bot Account
parent d54f6c446c
commit f54d93143f

View File

@ -29,9 +29,9 @@ using namespace std::chrono_literals;
class MockTask : public Task {
public:
std::atomic_bool should_complete = false;
int polled = 0;
int destroyed = 0;
std::optional<Waker> last_waker = std::nullopt;
std::atomic_int polled = 0;
std::atomic_int destroyed = 0;
Waker last_waker;
private:
Poll<> DoPend(Context& cx) override {
@ -65,7 +65,7 @@ TEST(Dispatcher, RunToCompletion_SleepsUntilWoken) {
FunctionThread delayed_wake([&task]() {
this_thread::sleep_for(100ms);
task.should_complete = true;
std::move(*task.last_waker).Wake();
std::move(task.last_waker).Wake();
});
thread::Thread work_thread(thread::stl::Options(), delayed_wake);