![]() |
![]() |
| |||||||||||
Wait for an Absolute Timecond_timedwait(3THR)
Use cond_timedwait(3THR) as you would use cond_wait(), except that cond_timedwait() does not block past the time of day specified by abstime. (For POSIX threads, see pthread_cond_timedwait(3THR).) cond_timedwait() always returns with the mutex locked and owned by the calling thread even when returning an error. The cond_timedwait() function blocks until the condition is signaled or until the time of day specified by the last argument has passed. The timeout is specified as the time of day so the condition can be retested efficiently without recomputing the time-out value. Wait for a Time Intervalcond_reltimedwait(3THR)
Use cond_reltimedwait(3THR) as you would use cond_timedwait(), except that cond_reltimedwait() takes a relative time interval value in its third argument rather than an absolute time of day value. (For POSIX threads see, pthread_cond_reltimedwait_np(3THR). cond_reltimedwait() always returns with the mutex locked and owned by the calling thread even when returning an error. The cond_reltimedwait() function blocks until the condition is signaled or until the time interval specified by the last argument has elapsed. Unblock One Threadcond_signal(3THR)
Use cond_signal(3THR) to unblock one thread that is blocked on the condition variable pointed to by cv. Call this function under protection of the same mutex used with the condition variable being signaled. Otherwise, the condition could be signaled between its test and cond_wait(), causing an infinite wait. Unblock All Threadscond_broadcast(3THR)
Use cond_broadcast(3THR) to unblock all threads that are blocked on the condition variable pointed to by cv. When no threads are blocked on the condition variable then cond_broadcast() has no effect. Similar Synchronization Functions--SemaphoresSemaphore operations are the same in both the Solaris Operating Environment and the POSIX environment. The function name changed from sema_ in the Solaris Operating Environment to sem_ in pthreads. Initialize a Semaphoresema_init(3THR)
Use sema_init(3THR) to initialize the semaphore variable pointed to by sp by count amount. type can be one of the following (note that arg is currently ignored). USYNC_PROCESS The semaphore can be used to synchronize threads in this process and other processes. Only one process should initialize the semaphore. arg is ignored. USYNC_THREAD The semaphore can be used to synchronize threads in this process, only. arg is ignored. Multiple threads must not initialize the same semaphore simultaneously. A semaphore must not be reinitialized while other threads might be using it. Semaphores With Intraprocess Scope
Semaphores With Interprocess Scope
Increment a Semaphoresema_post(3THR)
Use sema_post(3THR) to atomically increment the semaphore pointed to by sp. When any threads are blocked on the semaphore, one is unblocked. Block on a Semaphore Countsema_wait(3THR)
Use sema_wait(3THR) to block the calling thread until the count in the semaphore pointed to by sp becomes greater than zero, then atomically decrement it. Decrement a Semaphore Countsema_trywait(3THR)
Use sema_trywait(3THR) to atomically decrement the count in the semaphore pointed to by sp when the count is greater than zero. This function is a nonblocking version of sema_wait(). Destroy the Semaphore Statesem_destroy(3THR)
Use sem_destroy(3THR) to destroy any state associated with the semaphore pointed to by sp. The space for storing the semaphore is not freed. | |||||||||||
| |||||||||||