Medium
SCHED_FIFO threads on one core: spinlock vs CAS-loop push
Threads H (SCHED_FIFO priority 90) and L (SCHED_FIFO priority 10) are pinned to the same single core. L pushes to a shared stack continuously; H is woken by a timer and pushes once. Version 1 protects a std::vector with an atomic_flag spinlock; version 2 is a Treiber stack whose push() retries compare_exchange_weak. H wakes while L is midway through a push: holding the spinlock in version 1, between loading head and its CAS in version 2. What happens?
48 of 51 in Concurrency