Spin locks
A spin lock is also used for mutually exclusive access to some resource.
The
_spin_lock(3synch)
function differs from
mutex_lock(3synch)
in implementation.
If a spin lock is not available,
the calling thread is not blocked,
instead the caller busy waits (or ``spin''s)
until the lock becomes available.
_spin_lock( spin_t *lock);
_spin_unlock(spin_t *lock);
Considerations for the use of spin locks:
-
The busy waiting prevents the LWP from being used by another thread.
-
This facility is intended for use when the delay is expected
to be smaller than the time to context switch to another thread and back.
-
Use of this facility is not recommended on uniprocessor machines
or if only one processor of a multiprocessor machine might be available.
In those circumstances the spinning thread prevents the possible execution
of the thread that is holding the lock,
thereby delaying,
possibly deadlocking,
itself.
NOTE:
Extreme care should be exercised in using spin locks.
The minimally safe environment for using spin locks
may be bound threads running on a system
with more than one processor.
However, deadlocks are always possible.
Next topic:
Recursive mutual exclusion
Previous topic:
Mutual exclusion locks
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004