Closed zjp-CN closed 3 months ago
Without other sync mechanism, unsync_init alone could not hold the promise of running init once across multithreads as the comment says. Since two threads could find the state is UNINIT at the same time and then both execute init. So it satisfies the definition of atomic violation. However, if init is constrained to be a pure function and always returns the same value without any other side effects, then running init multiple times only leads to some overhead and no logic error might occur.
Cool. I'm grateful for your concise and clear explanation.
Closing this.
Thanks for this tool. I'm no expert on concurrency programming.
When using lockbud on its atomic-violation example, I noticed there is a bug reporting for getrandom crate:
which points to this piece of code on docs.rs. On latest getrandom codebase, it's here, which has almost the same logic.
So I'm reporting here to wonder which is correct between the documented code of getrandom and the result of lockbud.