rayon-rs / rayon

Rayon: A data parallelism library for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Potential to fix memory ordering for value

wang384670111 opened this issue · comments

self.value.fetch_add(ONE_INACTIVE, Ordering::SeqCst);

let old_value = Counters::new(self.value.fetch_sub(ONE_INACTIVE, Ordering::SeqCst));

let old_value = Counters::new(self.value.fetch_sub(ONE_SLEEPING, Ordering::SeqCst));

SeqCst is overly restrictive. I think that the memory ordering can be appropriately modified.

In counters model, value is used for multithreading counting purposes, so using Relaxed ordering is sufficient.

(happy to make a PR if this looks reasonable)

Have you read the nearby README? There is some discussion of why we're using SeqCst:
https://github.com/rayon-rs/rayon/blob/8ccfda38d55e96c5bf50d004f2df95d07468dd4a/rayon-core/src/sleep/README.md

So we are relying on memory fencing effects beyond the counter values themselves. It might still be possible that some of this could be weakened, but we need to be very careful about that.

Thanks for your reply! I miss some important information and I am a bit wrong, but I still believe that it is possible to weaken here, probably not Relaxed, I'll re-analyze the code again. :D