301 lines
8.2 KiB
HTML
301 lines
8.2 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_init_np()-Initialize Unnamed Semaphore with Maximum 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_init_np()--Initialize Unnamed Semaphore with Maximum Value</h2>
|
||
|
|
||
|
<div class="box" style="width: 60%;">
|
||
|
<br>
|
||
|
Syntax<br>
|
||
|
<pre>
|
||
|
#include <semaphore.h>
|
||
|
|
||
|
int sem_init_np(sem_t * <em>sem</em>, int <em>shared</em>,
|
||
|
unsigned int <em>value</em>,
|
||
|
sem_attr_np_t * <em>attr</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_init_np()</strong> function initializes an unnamed semaphore
|
||
|
and sets its initial value. The <strong>sem_init_np()</strong> function uses
|
||
|
the <em>attr</em> parameter to set the maximum value and title of the
|
||
|
semaphore. If an unnamed semaphore already exists at <em>sem</em>, then it
|
||
|
will be destroyed and a new semaphore will be initialized.</p>
|
||
|
|
||
|
<br>
|
||
|
<h3>Parameters</h3>
|
||
|
|
||
|
<dl>
|
||
|
<dt><strong>sem</strong></dt>
|
||
|
|
||
|
<dd>(Input) A pointer to the storage of an uninitialized unnamed semaphore. The
|
||
|
pointer must be aligned on a 16-byte boundary. This semaphore is
|
||
|
initialized.<br>
|
||
|
<br>
|
||
|
</dd>
|
||
|
|
||
|
<dt><strong>shared</strong></dt>
|
||
|
|
||
|
<dd>(Input) An indication to the system of how the semaphore is going to be
|
||
|
used. A value of zero indicates that the semaphore will be used only by threads
|
||
|
within the current process. A nonzero value indicates that the semaphore may be
|
||
|
used by threads from other processes.<br>
|
||
|
<br>
|
||
|
</dd>
|
||
|
|
||
|
<dt><strong>value</strong></dt>
|
||
|
|
||
|
<dd>(Input) The value used to initialize the value of the semaphore.<br>
|
||
|
<br>
|
||
|
</dd>
|
||
|
|
||
|
<dt><strong>attr</strong></dt>
|
||
|
|
||
|
<dd>(Input) Attributes for the semaphore.
|
||
|
|
||
|
<p>The members of the sem_attr_np_t structure are as follows.</p>
|
||
|
|
||
|
<table cellpadding="5">
|
||
|
<!-- cols="15 85" -->
|
||
|
<tr>
|
||
|
<td align="left" valign="top" nowrap><em>unsigned int reserved1[1]</em></td>
|
||
|
<td align="left" valign="top">A reserved field that must be set to zero.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>unsigned int maxvalue</em></td>
|
||
|
<td align="left" valign="top">The maximum value that the semaphore may obtain.
|
||
|
<em>maxvalue</em> must be greater than zero. If a <strong>sem_post()</strong>
|
||
|
or <strong>sem_post_np()</strong> operation would cause the value of a
|
||
|
semaphore to exceed its maximum value, the operation will fail, returning
|
||
|
EINVAL.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>unsigned int reserved2[2]</em></td>
|
||
|
<td align="left" valign="top">A reserved field that must be set to zero.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>char title[16]</em></td>
|
||
|
<td align="left" valign="top">The title of the semaphore. The title is a
|
||
|
null-terminated string that contains up to 16 bytes. Any bytes after the null
|
||
|
character are ignored. The title is retrieved using the Open List of
|
||
|
Interprocess Communication Objects (QP0ZOLIP) API.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>void * reserved3[2]</em></td>
|
||
|
<td align="left" valign="top">A reserved field that must be set to zero.</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</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_init_np()</strong> was
|
||
|
successful.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>-1</em></td>
|
||
|
<td align="left" valign="top"><strong>sem_init_np()</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_init_np()</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>
|
||
|
<p>The value specified for the argument is not correct.</p>
|
||
|
|
||
|
<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>
|
||
|
|
||
|
<p>The <em>value</em> parameter is greater than the <samp>maxvalue</samp>
|
||
|
field of the <em>attr</em> parameter.</p>
|
||
|
|
||
|
<p>The <samp>maxvalue</samp> field of the <em>attr</em> parameter is greater
|
||
|
than SEM_VALUE_MAX.</p>
|
||
|
|
||
|
<p>The <samp>maxvalue</samp> field of the <em>attr</em> parameter is equal to
|
||
|
zero.</p>
|
||
|
|
||
|
<p>The reserved fields of the <em>attr</em> argument are not set to zero.</p>
|
||
|
</dd>
|
||
|
|
||
|
<dt><em>[EFAULT]</em></dt>
|
||
|
|
||
|
<dd>
|
||
|
<p>The address used for an argument is not correct.</p>
|
||
|
|
||
|
<p>In attempting to use an argument in a call, the system detected an address
|
||
|
that is not valid.</p>
|
||
|
|
||
|
<p>While attempting to access a parameter passed to this function, the system
|
||
|
detected an address that is not valid.</p>
|
||
|
</dd>
|
||
|
|
||
|
<dt><em>[ENOSPC]</em></dt>
|
||
|
|
||
|
<dd>
|
||
|
<p>No space available.</p>
|
||
|
|
||
|
<p>The requested operations required additional space on the device and there
|
||
|
is no space left. This could also be caused by exceeding the user profile
|
||
|
storage limit when creating or transferring ownership of an object.</p>
|
||
|
|
||
|
<p>Insufficient space remains to hold the intended file, directory, or
|
||
|
link.</p>
|
||
|
|
||
|
<p>System semaphore resources have been exhausted.</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="ipcsemde.htm">sem_destroy()</a>--Destroy Unnamed Semaphore<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li><a href="ipcsemge.htm">sem_getvalue()</a>--Get Semaphore Value<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li><a href="ipcsemi.htm">sem_init()</a>--Initialize Unnamed Semaphore<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="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 initializes an unnamed semaphore, my_semaphore, that
|
||
|
will be used by threads of the current process and sets its value to 10. The
|
||
|
maximum value and title of the semaphore are set to 10 and "MYSEM".</p>
|
||
|
|
||
|
<pre>
|
||
|
#include <semaphore.h>
|
||
|
main() {
|
||
|
sem_t my_semaphore;
|
||
|
sem_attr_np_t attr;
|
||
|
int rc;
|
||
|
|
||
|
memset(&attr, 0, sizeof(attr));
|
||
|
attr.maxvalue = 10;
|
||
|
strcpy(attr.title, "MYSEM");
|
||
|
rc = sem_init_np(&my_semaphore, 0, 10, &attr);
|
||
|
|
||
|
}
|
||
|
</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>
|
||
|
|