Because we can not use
Once (in theory initialization function can fail, but work on re-try), it implements a custom spin-lock, thus I hope to get some code review. I have the following particular questions:
- Can we use
Ordering::Relaxedin first atomic loads considering that in case if state is not initialzied it’s followed by
Ordering::AcqRelfetch? (e.g. here)
- Am I correct that atomic stores can not be reordered here under no circumstances? (i.e. other threads can not read uninitialized file descriptor value)
- What is better to use
thread::yield_now()? (note actual sleep time will not be smaller than granularity of an underlying clock) The latter may use 100% of CPU during initialization if no other threads/processes want it, but on the other hand it “simpler” than sleep.