|
Threads-Devel : |
From: Matt Hurd (matt.hurd_at_[hidden])
Date: 2006-03-04 22:51:38
> windows or posix AFAIK. POSIX.1d introduced int pthread_mutex_trylock
> (pthread_mutex_t *mutex). There is a similar beast for rw stuff on posix.
copy paste error...
meant to refer to
_________________
int pthread_mutex_timedlock (pthread_mutex_t *mutex, const struct timespec
*abstime) Function
The pthread_mutex_timedlock is similar to the pthread_mutex_lock function but
instead of blocking for in indefinite time if the mutex is locked by another
thread, it returns when the time specified in abstime is reached.
This function can only be used on standard ("timed") and "error checking"
mutexes. It behaves just like pthread_mutex_lock for all other types.
If the mutex is successfully locked, the function returns zero. If the time
specified in abstime is reached without the mutex being locked, ETIMEDOUT is
returned.
This function was introduced in the POSIX.1d revision of the POSIX standard.
_________________
r/w posix mutexes have a timed lock interface too.
_________________
I'm pretty sure I'm wrong about the critical section on windows having a timed
locking interface. Can't see it. It does have a "try" interface though.
<quote>
A thread uses the EnterCriticalSection or TryEnterCriticalSection function to
request ownership of a critical section. It uses the LeaveCriticalSection
function to release ownership of a critical section. If the critical section
object is currently owned by another thread, EnterCriticalSection waits
indefinitely for ownership. In contrast, when a mutex object is used for
mutual exclusion, the wait functions accept a specified time-out interval.
The TryEnterCriticalSection function attempts to enter a critical section
without blocking the calling thread.
</quote>
from:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/critical_section_objects.asp
I did see that the newer versions of windows will have RWLocks and condition
variables though (Vista / Longhorn).
You can see them in the Condition var and SRW lock function reference here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/synchronization_functions.asp
Regards,
matt.