📄 sem_init.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>sem_init</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_008_297"> </a>NAME</h4><blockquote>sem_init - initialise an unnamed semaphore(<b>REALTIME</b>)</blockquote><h4><a name = "tag_000_008_298"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="semaphore.h.html">semaphore.h</a>>int sem_init(sem_t *<i>sem</i>, int <i>pshared</i>, unsigned int <i>value</i>);</code></pre></blockquote><h4><a name = "tag_000_008_299"> </a>DESCRIPTION</h4><blockquote>The<i>sem_init()</i>function is used to initialise the unnamed semaphore referred to by<i>sem</i>.The value of the initialised semaphore is<i>value</i>.Following a successful call to<i>sem_init()</i>,the semaphore may be used in subsequent calls to<i><a href="sem_wait.html">sem_wait()</a></i>,<i><a href="sem_trywait.html">sem_trywait()</a></i>,<i><a href="sem_post.html">sem_post()</a></i>,and<i><a href="sem_destroy.html">sem_destroy()</a></i>.This semaphore remains usable until the semaphore is destroyed.<p>If the<i>pshared</i>argument has a non-zero value,then the semaphore is shared between processes;in this case,any process that can access the semaphore<i>sem</i>can use<i>sem</i>for performing<i><a href="sem_wait.html">sem_wait()</a></i>,<i><a href="sem_trywait.html">sem_trywait()</a></i>,<i><a href="sem_post.html">sem_post()</a></i>,and<i><a href="sem_destroy.html">sem_destroy()</a></i>operations.<p>Only<i>sem</i>itself may be used for performing synchronisation.The result of referring to copies of<i>sem</i>in calls to<i><a href="sem_wait.html">sem_wait()</a></i>,<i><a href="sem_trywait.html">sem_trywait()</a></i>,<i><a href="sem_post.html">sem_post()</a></i>,and<i><a href="sem_destroy.html">sem_destroy()</a></i>,is undefined.<p>If the<i>pshared</i>argument is zero, then the semaphore is shared between threads of theprocess; any thread in this process can use<i>sem</i>for performing<i><a href="sem_wait.html">sem_wait()</a></i>,<i><a href="sem_trywait.html">sem_trywait()</a></i>,<i><a href="sem_post.html">sem_post()</a></i>,and<i><a href="sem_destroy.html">sem_destroy()</a></i>operations.The use of the semaphore by threads other than thosecreated in the same process is undefined.<p>Attempting to initialise an already initialised semaphore results inundefined behaviour.</blockquote><h4><a name = "tag_000_008_300"> </a>RETURN VALUE</h4><blockquote>Upon successful completion, the function initialises the semaphore in<i>sem</i>.Otherwise,it returns -1 and sets<i>errno</i>to indicate the error.</blockquote><h4><a name = "tag_000_008_301"> </a>ERRORS</h4><blockquote>The <i>sem_init()</i>function will fail if:<dl compact><dt>[EINVAL]<dd>The<i>value</i>argument exceeds<i>SEM_VALUE_MAX</i>.<dt>[ENOSPC]<dd>A resource required to initialise the semaphore has been exhausted,or the limit on semaphores (SEM_NSEMS_MAX) has been reached.<dt>[ENOSYS]<dd>The function<i>sem_init()</i>is not supported by this implementation.<dt>[EPERM]<dd>The process lacks the appropriate privilegesto initialise the semaphore.</dl></blockquote><h4><a name = "tag_000_008_302"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_008_303"> </a>APPLICATION USAGE</h4><blockquote>None.</blockquote><h4><a name = "tag_000_008_304"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_008_305"> </a>SEE ALSO</h4><blockquote><i><a href="sem_destroy.html">sem_destroy()</a></i>,<i><a href="sem_post.html">sem_post()</a></i>,<i><a href="sem_trywait.html">sem_trywait()</a></i>,<i><a href="sem_wait.html">sem_wait()</a></i>,<i><a href="semaphore.h.html"><semaphore.h></a></i>.</blockquote><h4>DERIVATION</h4><blockquote>Derived from the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995)</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -