Skip to content

Commit

Permalink
Fix data race in DriverTest.pauserNode test (#2466)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #2466

Fix data race exposed by TSAN:

```
WARNING: ThreadSanitizer: data race (pid=3539135)
  Write of size 8 at 0x7ffd6053de08 by main thread:
    #2 DriverTest_pauserNode_Test::TestBody() velox/exec/tests/DriverTest.cpp:677 (velox_exec_test+0x58205e)

  Previous read of size 8 at 0x7ffd6053de08 by thread T32:
    #2 DriverTest_pauserNode_Test::TestBody()::$_6::operator()() const velox/exec/tests/DriverTest.cpp:680 (velox_exec_test+0x5a4441)
```

Reviewed By: xiaoxmeng

Differential Revision: D39311986

fbshipit-source-id: c7f36bac377f243b879eb7c11bd8159e36b5fbee
  • Loading branch information
mbasmanova authored and facebook-github-bot committed Sep 7, 2022
1 parent 5b7b839 commit 9bce36f
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions velox/exec/tests/DriverTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,7 @@ TEST_F(DriverTest, pauserNode) {
Operator::registerOperator(std::make_unique<PauserNodeFactory>(
kThreadsPerTask, sequence, testInstance));

std::vector<int32_t> counters;
counters.reserve(kNumTasks);
std::vector<CursorParameters> params;
params.resize(kNumTasks);
std::vector<CursorParameters> params(kNumTasks);
int32_t hits;
for (int32_t i = 0; i < kNumTasks; ++i) {
params[i].queryCtx = std::make_shared<core::QueryCtx>(
Expand All @@ -671,10 +668,10 @@ TEST_F(DriverTest, pauserNode) {
params[i].maxDrivers =
kThreadsPerTask * 2; // a number larger than kThreadsPerTask
}
std::vector<int32_t> counters(kNumTasks, 0);
std::vector<std::thread> threads;
threads.reserve(kNumTasks);
for (int32_t i = 0; i < kNumTasks; ++i) {
counters.push_back(0);
threads.push_back(std::thread([this, &params, &counters, i]() {
try {
readResults(params[i], ResultOperation::kRead, 10'000, &counters[i], i);
Expand Down

0 comments on commit 9bce36f

Please sign in to comment.