diff options
author | kruall <kruall@ydb.tech> | 2022-12-29 14:14:39 +0300 |
---|---|---|
committer | kruall <kruall@ydb.tech> | 2022-12-29 14:14:39 +0300 |
commit | f3c5bbbd24345e6b826e143843b07d416e34a2b4 (patch) | |
tree | 4b9d765ac81cec83963e758097f1e564d56e07d2 | |
parent | 40865b5e4d6f90bfcce0ff4574206ec9957f32bf (diff) | |
download | ydb-f3c5bbbd24345e6b826e143843b07d416e34a2b4.tar.gz |
Fix data races,
-rw-r--r-- | library/cpp/actors/core/executor_pool_basic.cpp | 2 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_pool_basic_ut.cpp | 2 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_pool_united.cpp | 2 | ||||
-rw-r--r-- | library/cpp/actors/core/performance_ut.cpp | 13 |
4 files changed, 10 insertions, 9 deletions
diff --git a/library/cpp/actors/core/executor_pool_basic.cpp b/library/cpp/actors/core/executor_pool_basic.cpp index 00e557fcb42..3ee504982ec 100644 --- a/library/cpp/actors/core/executor_pool_basic.cpp +++ b/library/cpp/actors/core/executor_pool_basic.cpp @@ -244,7 +244,7 @@ namespace NActors { if (x == oldX) { break; } - } while (!StopFlag); + } while (!RelaxedLoad(&StopFlag)); if (needToWait) { if (GoToWaiting(threadCtx, timers, needToBlock)) { // interrupted diff --git a/library/cpp/actors/core/executor_pool_basic_ut.cpp b/library/cpp/actors/core/executor_pool_basic_ut.cpp index b87507bdbf9..6361bc66626 100644 --- a/library/cpp/actors/core/executor_pool_basic_ut.cpp +++ b/library/cpp/actors/core/executor_pool_basic_ut.cpp @@ -474,7 +474,7 @@ Y_UNIT_TEST_SUITE(ChangingThreadsCountInBasicExecutorPool) { const size_t N = 6; const size_t threadsCounts[N] = { 1, 3, 2, 3, 1, 4 }; for (ui32 idx = 0; idx < 4 * N; ++idx) { - size_t currentThreadCount = threadsCounts[idx]; + size_t currentThreadCount = threadsCounts[idx % N]; ctx.ExecutorPool->SetThreadCount(currentThreadCount); AtomicSet(ctx.State.ExpectedMaximum, currentThreadCount); diff --git a/library/cpp/actors/core/executor_pool_united.cpp b/library/cpp/actors/core/executor_pool_united.cpp index 4910ddf9651..79f26b83450 100644 --- a/library/cpp/actors/core/executor_pool_united.cpp +++ b/library/cpp/actors/core/executor_pool_united.cpp @@ -1284,7 +1284,7 @@ namespace NActors { ElapsedTs += cpuStats.ElapsedTicks; ParkedTs += cpuStats.ParkedTicks; worstActivationTimeUs = Max(worstActivationTimeUs, cpuStats.WorstActivationTimeUs); - cpuStats.WorstActivationTimeUs = 0; + AtomicStore<decltype(cpuStats.WorstActivationTimeUs)>(&cpuStats.WorstActivationTimeUs, 0ul); logs.push_back(&cpu->LoadLog); } ui64 minPeriodTs = Min(ui64(Us2Ts(Balancer->GetPeriodUs())), ui64((1024ull-2ull)*64ull*128ull*1024ull)); diff --git a/library/cpp/actors/core/performance_ut.cpp b/library/cpp/actors/core/performance_ut.cpp index c5096528385..51d10a5e80a 100644 --- a/library/cpp/actors/core/performance_ut.cpp +++ b/library/cpp/actors/core/performance_ut.cpp @@ -26,7 +26,7 @@ Y_UNIT_TEST_SUITE(ActorSystemPerformance) { setup->Executors.Reset(new TAutoPtr<IExecutorPool>[2]); setup->Executors[0].Reset(new TBasicExecutorPool(0, 4, 20)); setup->Executors[1].Reset(new TIOExecutorPool(1, 10)); - + setup->Scheduler.Reset(new TBasicSchedulerThread(TSchedulerConfig(512, 100))); ActorSystem.reset(new TActorSystem{ setup }); @@ -65,8 +65,8 @@ Y_UNIT_TEST_SUITE(ActorSystemPerformance) { ui32 Counter = 0; ui32 CounterLimit = 10000000; const TInstant Start = Now(); - TDuration Duration; - bool Ready = false; + std::atomic<TDuration> Duration; + std::atomic<bool> Ready = false; public: bool MakeStep() { if (++Counter >= CounterLimit) { @@ -79,11 +79,12 @@ Y_UNIT_TEST_SUITE(ActorSystemPerformance) { return Now() - Start; } double GetOperationDuration() const { - return 1.0 * Duration.MicroSeconds() / Counter * 1000; + return 1.0 * Duration.load().MicroSeconds() / Counter * 1000; } void Finish() { - Ready = true; - Duration = GetDurationInProgress(); + if (!Ready.exchange(true)) { + Duration = GetDurationInProgress(); + } } bool IsFinished() const { return Ready; |