mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-06-15 08:17:05 +00:00
test: fix racy loop-variable capture in SubscriptionThreadSafety
- the subscriber threads captured the loop counter by reference while the spawning loop kept incrementing it: a genuine data race - depending on timing, threads could also end up with duplicate subscriber names; capture the counter by value instead
This commit is contained in:
committed by
Dennis Klein
parent
f08d42fcb8
commit
19e607e486
@@ -156,7 +156,7 @@ TEST_F(PluginServices, SubscriptionThreadSafety)
|
|||||||
std::array<std::unique_ptr<std::thread>, subscribers> threads;
|
std::array<std::unique_ptr<std::thread>, subscribers> threads;
|
||||||
auto id = 0;
|
auto id = 0;
|
||||||
for (auto& thread : threads) {
|
for (auto& thread : threads) {
|
||||||
thread = std::make_unique<std::thread>([&](){
|
thread = std::make_unique<std::thread>([&, id](){
|
||||||
auto const subscriber = fair::mq::tools::ToString("subscriber_", id);
|
auto const subscriber = fair::mq::tools::ToString("subscriber_", id);
|
||||||
for (auto i = 0; i < attempts; ++i) {
|
for (auto i = 0; i < attempts; ++i) {
|
||||||
mServices.SubscribeToDeviceStateChange(subscriber, [](DeviceState){});
|
mServices.SubscribeToDeviceStateChange(subscriber, [](DeviceState){});
|
||||||
|
|||||||
Reference in New Issue
Block a user