cross-thread locking
    Daniel Eischen 
    eischen at vigrid.com
       
    Fri Feb 20 07:02:03 PST 2004
    
    
  
On Fri, 20 Feb 2004, Dag-Erling [iso-8859-1] Sm=F8rgrav wrote:
> - What happens when a thread locks a mutex and then starts another
>   thread?  Does the new thread in any way inherit the lock, or will it
>   have to acquire its own?
No, it doesn't inherit any locks.
> - What about spin locks?  Are there any semantic differences between
>   mutexes and spin locks in POSIX, or are spin locks simply mutexes
>   that spin instead of sleeping?
POSIX differentiates between spinlocks and mutexes, and that is
why there is a pthread_spinlock_t instead of using pthread_mutex_t
for both lock operations.  I believe the implementation is allowed
to spin indefinitely or schedule another thread if the lock is
busy.
I can't find a rationale for spinlocks; I _thought_ there was
one in some draft of the spec that I had read.  I wouldn't
really advocate using spinlocks due to possible priority
inversion problems and wasting cycles.
--=20
Dan Eischen
    
    
More information about the freebsd-threads
mailing list