Skip to content

new_thread scheduler thread safety #492

@lebdron

Description

@lebdron

Thread sanitizer detects a data race in the following code:

rxcpp::composite_subscription lifetime;
auto worker =
    rxcpp::observe_on_new_thread().create_coordinator(lifetime).get_worker();
std::vector<std::thread> threads;
for (int i = 0; i < 20; ++i) {
  threads.emplace_back([&worker] {
    worker.schedule([&worker](const auto &) {
      for (size_t i = 0; i < 4294967292l / 6; ++i)
        ;
      printf("Work\n");
    });
  });
}
for (auto &t : threads) {
  t.join();
}
lifetime.unsubscribe();

https://gist.github.com/lebdron/883aa78504bc8b9b564e744e2951fb52

Should this bool be made atomic, or there is some other issue with the scheduler?

mutable bool isallowed;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions