Skip to content

Commit

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

Fix data race exposed by TSAN:

```
WARNING: ThreadSanitizer: data race (pid=3333333)
  Write of size 8 at 0x7ffedeec8260 by main thread:
    #2 DriverTest_yield_Test::TestBody() velox/exec/tests/DriverTest.cpp:478 (velox_exec_test+0x5815ab)

  Previous read of size 8 at 0x7ffedeec8260 by thread T32:
    #2 DriverTest_yield_Test::TestBody()::$_3::operator()() const velox/exec/tests/DriverTest.cpp:480 (velox_exec_test+0x599aae)
```

Reviewed By: xiaoxmeng

Differential Revision: D39311571

fbshipit-source-id: 1062e97c874d59333d0534ce23660f2fbbd1ae18
  • Loading branch information
mbasmanova authored and facebook-github-bot committed Sep 7, 2022
1 parent d2217d1 commit 5b7b839
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 @@ -456,10 +456,7 @@ TEST_F(DriverTest, pause) {
TEST_F(DriverTest, yield) {
constexpr int32_t kNumTasks = 20;
constexpr int32_t kThreadsPerTask = 5;
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].planNode = makeValuesFilterProject(
Expand All @@ -472,10 +469,10 @@ TEST_F(DriverTest, yield) {
&hits);
params[i].maxDrivers = 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]() {
readResults(params[i], ResultOperation::kYield, 10'000, &counters[i], i);
}));
Expand Down

0 comments on commit 5b7b839

Please sign in to comment.