233 lines
5.7 KiB
HTML
233 lines
5.7 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
|
|
<title>sem_getvalue()-Get Semaphore Value</title>
|
|
<!-- Begin Header Records ========================================== -->
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<!-- Change History: -->
|
|
<!-- YYMMDD USERID Change description -->
|
|
<!-- Direct1 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
|
|
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
|
|
<!-- Edited by Kersten Feb 02 -->
|
|
<!-- This file has undergone html cleanup on 05/01/02 by JET -->
|
|
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
|
</head>
|
|
<body>
|
|
<!--End Header Records -->
|
|
<!-- Java sync-link -->
|
|
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
|
|
</script>
|
|
|
|
<a name="Top_Of_Page"></a>
|
|
|
|
<h2>sem_getvalue()--Get Semaphore Value</h2>
|
|
|
|
<div class="box" style="width: 70%;">
|
|
<br>
|
|
Syntax<br>
|
|
<pre>
|
|
#include <semaphore.h>
|
|
|
|
int sem_getvalue(sem_t * <em>sem</em>, int * <em>value</em>);
|
|
</pre>
|
|
|
|
<br>
|
|
Service Program Name: QP0ZPSEM<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Default Public Authority: *USE<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Threadsafe: Yes<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
</div>
|
|
|
|
<p>The <strong>sem_getvalue()</strong> function retrieves the value of a named
|
|
or unnamed semaphore. If the current value of the semaphore is zero and there
|
|
are threads waiting on the semaphore, a negative value is returned. The
|
|
absolute value of this negative value is the number of threads waiting on the
|
|
semaphore.</p>
|
|
|
|
<p><strong>Parameters</strong></p>
|
|
|
|
<dl>
|
|
<dt><strong>sem</strong></dt>
|
|
|
|
<dd>(Input) A pointer to an initialized unnamed semaphore or an opened named
|
|
semaphore.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><strong>value</strong></dt>
|
|
|
|
<dd>(Output) A pointer to the integer that contains the value of the
|
|
semaphore.</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
<h3>Authorities</h3>
|
|
|
|
<p>None</p>
|
|
|
|
<br>
|
|
<h3>Return Value</h3>
|
|
|
|
<table cellpadding="5">
|
|
<!-- cols="5 95" -->
|
|
<tr>
|
|
<td align="left" valign="top"><em>0</em></td>
|
|
<td align="left" valign="top"><strong>sem_getvalue()</strong> was
|
|
successful.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top"><em>-1</em></td>
|
|
<td align="left" valign="top"><strong>sem_getvalue()</strong> was not
|
|
successful. The <em>errno</em> variable is set to indicate the error.</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<br>
|
|
<br>
|
|
|
|
|
|
<h3>Error Conditions</h3>
|
|
|
|
<p>If <strong>sem_getvalue()</strong> is not successful, <em>errno</em> usually
|
|
indicates one of the following errors. Under some conditions, <em>errno</em>
|
|
could indicate an error other than those listed here.</p>
|
|
|
|
<dl>
|
|
<dt><em>[EINVAL]</em></dt>
|
|
|
|
<dd>The value specified for the argument is not correct.
|
|
|
|
<p>A function was passed incorrect argument values, or an operation was
|
|
attempted on an object and the operation specified is not supported for that
|
|
type of object.</p>
|
|
|
|
<p>An argument value is not valid, out of range, or NULL.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
<h3>Error Messages</h3>
|
|
|
|
<p>None.</p>
|
|
|
|
<br>
|
|
<h3>Related Information</h3>
|
|
|
|
<ul>
|
|
<li>The <<strong>semaphore.h</strong>> file (see <a href="unix13.htm">
|
|
Header Files for UNIX-Type Functions</a>)<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ipcsemcl.htm">sem_close()</a>--Close Named Semaphore<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ipcsemde.htm">sem_destroy()</a>--Destroy Unnamed Semaphore<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ipcsemi.htm">sem_init()</a>--Initialize Unnamed Semaphore<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ipcsemin.htm">sem_init_np()</a>--Initialize Unnamed Semaphore with
|
|
Maximum Value<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ipcsemo.htm">sem_open()</a>--Open Named Semaphore<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ipcsemon.htm">sem_open_np()</a>--Open Named Semaphore with Maximum
|
|
Value<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ipcsemp.htm">sem_post()</a>--Post to Semaphore<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ipcsempn.htm">sem_post_np()</a>--Post Value to Semaphore<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ipcsemtr.htm">sem_trywait()</a>--Try to Decrement Semaphore<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ipcsemun.htm">sem_unlink()</a>--Unlink Named Semaphore<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ipcsemw.htm">sem_wait()</a>--Wait for Semaphore<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ipcsemwn.htm">sem_wait_np()</a>--Wait for Semaphore with
|
|
Timeout</li>
|
|
</ul>
|
|
|
|
<br>
|
|
<h3>Example</h3>
|
|
|
|
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
|
|
for information pertaining to code examples.</p>
|
|
|
|
<p>The following example retrieves the value of a semaphore before and after it
|
|
is decremented by <strong>sem_wait()</strong>.</p>
|
|
|
|
<pre>
|
|
#include <stdio.h>
|
|
#include <semaphore.h>
|
|
main() {
|
|
sem_t my_semaphore;
|
|
int value;
|
|
|
|
sem_init(&my_semaphore, 0, 10);
|
|
sem_getvalue(&my_semaphore, &value);
|
|
printf("The initial value of the semaphore is %d\n", value);
|
|
sem_wait(&my_semaphore);
|
|
sem_getvalue(&my_semaphore, &value);
|
|
printf("The value of the semaphore after the wait is %d\n", value);
|
|
|
|
}
|
|
</pre>
|
|
|
|
<br>
|
|
<h3>Output:</h3>
|
|
|
|
<pre>
|
|
The initial value of the semaphore is 10
|
|
The value of the semaphore after the wait is 9
|
|
</pre>
|
|
|
|
<br>
|
|
<hr>
|
|
API introduced: V4R4
|
|
|
|
<hr>
|
|
<center>
|
|
<table cellpadding="2" cellspacing="2">
|
|
<tr align="center">
|
|
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
|
|
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a></td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
</body>
|
|
</html>
|
|
|