eclipse-iceoryx / iceoryx2

Eclipse iceoryx2™ - true zero-copy inter-process-communication in pure Rust
https://iceoryx.io
Apache License 2.0
448 stars 22 forks source link

Race Condition in `UniqueSystemId` #181

Closed elfenpiff closed 2 months ago

elfenpiff commented 2 months ago

Required information

Conditions where it occurred / Performed steps: Assume we have 2 threads creating a UniqueSystemId concurrently. Since all threads come from the same process, the first 32 bits are the same (PID).

  1. Thread A starts and acquires the current nanosecond value nv.
  2. Thread A is concurrently by Thread B.
  3. Thread B acquires the same nanosecond value nv, updates the LAST_NANOSECONDS value with it, and creates a new UniqueSystemId.
  4. Thread B creates another UniqueSystemId and updates the LAST_NANOSECONDS again.
  5. Thread A continues, thinks that nv with its time stamp is unique since LAST_NANOSECONDS is not equal to nv and creates UniqueSystemId with the same value as Thread B did in step 3.