You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The lint would check that a loop has no side effects other than atomic access and warn to park the thread or call std::hint::spin_loop().
Categories (optional)
Kind: perf
What is the advantage of the recommended code over the original code
If the thread is parked it will stop consuming resources and avoid priority inversion.
If spin_loop() hint is used the code will consume less power on some architectures or perform better.
Presence of spin_loop() could also better communicate to reviewer that author did not forget to park the thread.
Drawbacks
None that I know of but I'm not very knowledgeable about the topic.
In some cases it may be better to use futex instead of thread::park().
Example
while some_atomic.load(atomic::Ordering::Acquire) == NOT_READY{}
Could be written as:
while some_atomic.load(atomic::Ordering::Acquire) == NOT_READY{
std::hint::spin_loop();}
or
while some_atomic.load(atomic::Ordering::Acquire) == NOT_READY{
thread::park();}
with thread::unpark() at the place where a value is stored into atomic
What it does
The lint would check that a loop has no side effects other than atomic access and warn to park the thread or call
std::hint::spin_loop()
.Categories (optional)
What is the advantage of the recommended code over the original code
If the thread is parked it will stop consuming resources and avoid priority inversion.
If
spin_loop()
hint is used the code will consume less power on some architectures or perform better.Presence of
spin_loop()
could also better communicate to reviewer that author did not forget to park the thread.Drawbacks
None that I know of but I'm not very knowledgeable about the topic.
In some cases it may be better to use futex instead of
thread::park()
.Example
Could be written as:
or
with
thread::unpark()
at the place where a value is stored into atomicAdditional context
Loosely related: rust-lang/miri#1388 (comment)
The text was updated successfully, but these errors were encountered: