| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 3: Basic Library Functions Oracle Solaris 11 Information Library |
enable_extended_FILE_stdio(3C)
posix_spawnattr_getschedparam(3C)
posix_spawnattr_getschedpolicy(3C)
posix_spawnattr_getsigdefault(3C)
posix_spawnattr_getsigignore_np(3C)
posix_spawnattr_getsigmask(3C)
posix_spawnattr_setschedparam(3C)
posix_spawnattr_setschedpolicy(3C)
posix_spawnattr_setsigdefault(3C)
posix_spawnattr_setsigignore_np(3C)
posix_spawnattr_setsigmask(3C)
posix_spawn_file_actions_addclose(3C)
posix_spawn_file_actions_addclosefrom_np(3C)
posix_spawn_file_actions_adddup2(3C)
posix_spawn_file_actions_addopen(3C)
posix_spawn_file_actions_destroy(3C)
posix_spawn_file_actions_init(3C)
pthread_attr_getdetachstate(3C)
pthread_attr_getinheritsched(3C)
pthread_attr_getschedparam(3C)
pthread_attr_getschedpolicy(3C)
pthread_attr_setdetachstate(3C)
pthread_attr_setinheritsched(3C)
pthread_attr_setschedparam(3C)
pthread_attr_setschedpolicy(3C)
pthread_barrierattr_destroy(3C)
pthread_barrierattr_getpshared(3C)
pthread_barrierattr_setpshared(3C)
pthread_condattr_getpshared(3C)
pthread_condattr_setpshared(3C)
pthread_cond_reltimedwait_np(3C)
pthread_key_create_once_np(3C)
pthread_mutexattr_getprioceiling(3C)
pthread_mutexattr_getprotocol(3C)
pthread_mutexattr_getpshared(3C)
pthread_mutexattr_getrobust(3C)
pthread_mutexattr_setprioceiling(3C)
pthread_mutexattr_setprotocol(3C)
pthread_mutexattr_setpshared(3C)
pthread_mutexattr_setrobust(3C)
pthread_mutex_getprioceiling(3C)
pthread_mutex_setprioceiling(3C)
pthread_rwlockattr_destroy(3C)
pthread_rwlockattr_getpshared(3C)
pthread_rwlockattr_setpshared(3C)
pthread_rwlock_reltimedrdlock_np(3C)
pthread_rwlock_reltimedwrlock_np(3C)
pthread_rwlock_timedrdlock(3C)
pthread_rwlock_timedwrlock(3C)
rctlblk_get_enforced_value(3C)
- lock a mutex
cc-mt [flag... ]file... [library... ]#include <pthread.h>#include <time.h>intpthread_mutex_timedlock(pthread_mutex_t *restrictmutex,const struct timespec *restrictabs_timeout);
intpthread_mutex_reltimedlock_np(pthread_mutex_t *restrictmutex,const struct timespec *restrictrel_timeout);
Thepthread_mutex_timedlock() function locks the mutex object referenced bymutex. If themutex is already locked, the calling thread blocks until the mutex becomesavailable as in thepthread_mutex_lock(3C). If the mutex cannot be locked withoutwaiting for another thread to unlock the mutex, this wait is terminatedwhen the specified timeout expires.
Thepthread_mutex_reltimedlock_np() function is identical to thepthread_mutex_timedlock() function, except that thetimeout is specified as a relative time interval.
Forpthread_mutex_timedlock(), the timeout expires when the absolute time specified byabs_timeoutpasses, as measured by the clock on which timeouts are based (thatis, when the value of that clock equals or exceedsabs_timeout), or ifthe absolute time specified byabs_timeout has already been passed at thetime of the call.
Forpthread_mutex_reltimedlock_np(), the timeout expires when the time interval specified byrel_timeoutpasses, as measured by theCLOCK_REALTIME clock, or if the time intervalspecified byrel_timeout is negative at the time of the call.
The resolution of the timeout is the resolution of theCLOCK_REALTIME clock.Thetimespec data type is defined in the<time.h>header.
Under no circumstance will either function fail with a timeout if themutex can be locked immediately. The validity of thetimeout parameter isnot checked if the mutex can be locked immediately.
As a consequence of the priority inheritance rules (for mutexes initialized withthePRIO_INHERIT protocol), if a timed mutex wait is terminated because itstimeout expires, the priority of the owner of the mutex is adjustedas necessary to reflect the fact that this thread is no longer amongthe threads waiting for the mutex.
Upon successful completion, thepthread_mutex_timedlock() andpthread_mutex_reltimedlock_np() functions return 0. Otherwise, anerror number is returned to indicate the error.
Thepthread_mutex_timedlock() andpthread_mutex_reltimedlock_np() functions will fail for the same reasons aspthread_mutex_lock(3C). In addition, they will fail if:
The caller would have blocked and thetimeout parameter specified a nanoseconds field value less than zero or greater than or equal to 1,000 million.
The mutex could not be locked before the specifiedtimeout expired.
Seeattributes(5) for descriptions of the following attributes:
|
time(2),pthread_mutex_destroy(3C),pthread_mutex_lock(3C),pthread_mutex_trylock(3C),attributes(5),standards(5)
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |