'\" te .\" Copyright (c) 1997, Sun Microsystems, Inc. All Rights Reserved .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] .TH _LWP_SEMA_WAIT 2 "May 8, 1998" .SH NAME _lwp_sema_wait, _lwp_sema_trywait, _lwp_sema_init, _lwp_sema_post \- semaphore operations .SH SYNOPSIS .LP .nf #include \fBint\fR \fB_lwp_sema_wait\fR(\fBlwp_sema_t *\fR\fIsema\fR); .fi .LP .nf \fBint\fR \fB_lwp_sema_trywait\fR(\fBlwp_sema_t *\fR\fIsema\fR); .fi .LP .nf \fBint\fR \fB_lwp_sema_init\fR(\fBlwp_sema_t *\fR\fIsema\fR, \fBint\fR \fIcount\fR); .fi .LP .nf \fBint\fR \fB_lwp_sema_post\fR(\fBlwp_sema_t *\fR\fIsema\fR); .fi .SH DESCRIPTION .sp .LP Conceptually, a semaphore is an non-negative integer count that is atomically incremented and decremented. Typically this represents the number of resources available. The \fB_lwp_sema_init()\fR function initializes the count, \fB_lwp_sema_post()\fR atomically increments the count, and \fB_lwp_sema_wait()\fR waits for the count to become greater than 0 and then atomically decrements it. .sp .LP LWP semaphores must be initialized before use. The \fB_lwp_sema_init()\fR function initializes the count associated with the LWP semaphore pointed to by \fIsema\fR to \fIcount\fR. .sp .LP The \fB_lwp_sema_wait()\fR function blocks the calling LWP until the semaphore count becomes greater than 0 and then atomically decrements it. .sp .LP The \fB_lwp_sema_trywait()\fR function atomically decrements the count if it is greater than zero. Otherwise it returns an error. .sp .LP The \fB_lwp_sema_post()\fR function atomically increments the semaphore count. If there are any LWPs blocked on the semaphore, one is unblocked. .SH RETURN VALUES .sp .LP Upon successful completion, \fB0\fR is returned. A non-zero value indicates an error. .SH ERRORS .sp .LP The \fB_lwp_sema_init()\fR, \fB_lwp_sema_trywait()\fR, \fB_lwp_sema_wait()\fR, and \fB_lwp_sema_post()\fR functions will fail if: .sp .ne 2 .na \fB\fBEINVAL\fR\fR .ad .RS 10n The \fIsema\fR argument points to an invalid semaphore. .RE .sp .ne 2 .na \fB\fBEFAULT\fR\fR .ad .RS 10n The \fIsema\fR argument points to an illegal address. .RE .sp .LP The \fB_lwp_sema_wait()\fR function will fail if: .sp .ne 2 .na \fB\fBEINTR\fR\fR .ad .RS 9n The function execution was interrupted by a signal or \fBfork\fR(2). .RE .sp .LP The \fB_lwp_sema_trywait()\fR function will fail if: .sp .ne 2 .na \fB\fBEBUSY\fR\fR .ad .RS 9n The function was called on a semaphore with a zero count. .RE .sp .LP The \fB_lwp_sema_post()\fR function will fail if: .sp .ne 2 .na \fB\fBEOVERFLOW\fR\fR .ad .RS 13n The value of the \fIsema\fR argument exceeds \fBSEM_VALUE_MAX\fR. .RE .SH SEE ALSO .sp .LP \fBfork\fR(2)