Use AtomicFlag to make papi thread safe.