Skip to content

Fix data races

Kevin Pedro requested to merge pedrok/fix-data-races-3 into master

This PR addresses several issues:

  1. A data race is possible in EventServer::AddEvent() in ExternalLoop mode, because it is called by EventSet::AddSetToServer() which was outside of any spinlock. The call is moved inside an existing spinlock to fix this.
  2. The local variable ninflight, used for the stopping condition when processing an event, was calculated as the difference of two atomics, a quantity which itself is not necessarily atomic. With @agheata, I determined that the other stopping condition ndone >= fNprimaries is no longer necessary (since events are now loaded with all primaries before processing starts, which at some earlier stage was not necessarily the case). Therefore, it is not actually needed to track fNdone or fNtracks, just a new fNinflight that is atomically incremented and decremented. This reduces the number of atomic operations needed and simplifies the bookkeeping in Event. (Additionally, the atomic write-read operation on fNinflight is intended to force a cache synchronization before RunManager::EventTransported() is called, which can merge the user data across multiple threads.)
  3. Some unused variables were removed (cleanup).

Merge request reports