struct Syn::Core::SpinLock
- Syn::Core::SpinLock
- Struct
- Value
- Object
Overview
Tries to acquire an atomic lock by spining, trying to avoid slow thread context switches that involve the kernel scheduler but eventually fallback to yielding to another thread, to avoid spinning (and thus burning) a CPU that would be counter-productive (scheduler may believe the thread is doing some heavy computation and delay it's suspension).
This is a public alternative to the private Crystal::SpinLock in stdlib. That beind said, you're not supposed to ever need it.
The implementation is a NOOP until the program has enabling MT during
compilation (i.e. -Dpreview_mt
flag).
Defined in:
core/spin_lock.crConstructors
Instance Method Summary
- #initialize
- #lock : Nil
-
#synchronize(& : -> U) : U forall U
Locks, yields and unlocks.
- #unlock : Nil
Constructor Detail
Instance Method Detail
Locks, yields and unlocks.
NOTE make sure that the block doesn't execute anything more than necessary, since concurrent threads will be blocked for its whole duration!