Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 07 Dec 2003 09:17:55 +0800
From:      David Xu <davidxu@freebsd.org>
To:        Daniel Eischen <eischen@vigrid.com>
Cc:        threads@freebsd.org
Subject:   Re: pthread_mutex_trylock() should never block
Message-ID:  <3FD27FC3.6020100@freebsd.org>
In-Reply-To: <Pine.GSO.4.10.10312061337060.20499-100000@pcnet5.pcnet.com>
References:  <Pine.GSO.4.10.10312061337060.20499-100000@pcnet5.pcnet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Daniel Eischen wrote:

>On Sat, 6 Dec 2003, Daniel Eischen wrote:
>
>  
>
>>On Sat, 6 Dec 2003, Igor Sysoev wrote:
>>    
>>
>>>SUSv2 states:
>>>[ http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_mutex_lock.html ]
>>>
>>>--------
>>>The function pthread_mutex_trylock() is identical to pthread_mutex_lock()
>>>except that if the mutex object referenced by mutex is currently locked
>>>(by any thread, including the current thread), the call returns immediately.
>>>      
>>>
>>The low-level locks are necessary (at least in libpthread implementation)
>>to safely test the mutex for ownership.
>>    
>>
>
>And not only that, but the low-level locks are also necessary to take
>the mutex if it is not owned.
>
>  
>
In libkse, if a thread is in critical region, scheduler will let it run 
until
it leaves critical region unless it is blocked in kernel or volunteerly
switchouts itself. In the case you are talking about, the thread will
never be blocked on a UP machine. This only happens under SMP.

David Xu




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3FD27FC3.6020100>