GregoireHENRY / rust-spice

WOW! The complete NASA/NAIF Spice toolkit is actually usable on Rust
Apache License 2.0
48 stars 16 forks source link

lock: change locking to a mutex #13

Open mkalte666 opened 1 year ago

mkalte666 commented 1 year ago

I suggest changing the locking mechanism behind SpiceLock to a mutex.

Mutexes have the advantage that they allow for blocking waits natively. These are typically handled by some external sync mechanism. Thusly, threads will be put to sleep by the OS until the other place has unlocked it. The old atomic-bool solution required a busy-wait to achieve this.

This changed implementation has the disadvantage that it requires rustc version >= 1.70.0 which, as of commiting this, still is in beta (it is stabilized however, so its just a small wait, not an indeterminate one!) . However OnceLock avoids having to pull in once_cell or lazy_static as dependencies. So i think its best to wait until june to merge this.

Have a great week!

EDIT: Oh and since you did the original legwork, what are your thoughts on this @mclrc ?

~mkalte

mclrc commented 1 year ago

Sorry for the super late response, I missed the notification somehow. I don't really know a lot about the lower level details, but it sounds like it makes sense! And by now everything needed is stable, right?