📄 mutex.html
字号:
<HTML><HEAD><TITLE>mutex Class</TITLE></HEAD><BODY bgcolor="#ffffff"><H1>mutex Class Reference</H1><p>[<A HREF="index.html">threads Index</A>] [<A HREF="heir.html">threads Hierarchy</A>]</p><HR><P>Class for mutual exclusion of parallel processes. <a href="#short">More...</a></P><P><code> #include <<a href="-usr-local-include-thread_mutex-h.html">/usr/local/include/thread_mutex.h</a>></code></P><H2>Public Members</H2><UL><LI>enum <b><a name="ref0">mutex_kind</a></b> { fast, recursive, errorcheck }</LI><LI><b><a name="ref1">mutex</a></b> (attributes::scope) </LI><LI><b><a name="ref2">mutex</a></b> () </LI><LI><b><a name="ref3">~mutex</a></b> () </LI><LI>attributes::scope <b><a href="#ref4">scope</a></b> () </LI><LI>int <b><a href="#ref5">trylock</a></b> () </LI><LI>int <b><a href="#ref6">lock</a></b> () </LI><LI>int <b><a href="#ref7">unlock</a></b> () </LI><LI>int <b><a href="#ref8">kind</a></b> () </LI><LI>int <b><a href="#ref9">kind</a></b> (mutex_kind) </LI><LI>static void <b><a href="#ref10">project_part</a></b> (const char *) </LI></UL><HR><H2><a name="short">Detailed Description</a></H2><P> Mutex, is a class for mutual exclusion of parallel processes. That need to access the same memory, while keeping exclusive access.</p><p></P><HR><H2>attributes::scope <a name="ref4"></a><a name="scope">scope</a>() </H2><p> Each mutex variable, can exist within a single process hierarchy or be viewed system wide. The range of the scope is:</p><p> <pre> process_shared - interprocess process_private - only within this process and its threads. </pre></p><p></p><dl><dt><b>Returns</b>:<dd>The scope of this mutex.</dl><H2>int <a name="ref5"></a><a name="trylock">trylock</a>() </H2><p> Try and lock the mutex, and return immediately to the caller with the result.</p><p></p><dl><dt><b>Returns</b>:<dd>EBUSY if the mutex is busy, EINVAL if it is an unknown kind and 0 on success.</dl><H2>int <a name="ref6"></a><a name="lock">lock</a>() </H2><p> Lock the semaphore, and wait for ut if it is already locked by another. This will suspend the calling process until such time the lock is successful, or an error occurs.</p><p></p><dl><dt><b>Returns</b>:<dd>0 on success, EINVAL if the mutex is an unknown kind.</dl><H2>int <a name="ref7"></a><a name="unlock">unlock</a>() </H2><p> Unlock a previously locked mutex, and restart any threads that are waiting on this mutex.</p><p></p><dl><dt><b>Returns</b>:<dd>0 on success, EBUSY if it is locked by another process, and EINVAL if the mutex is an unknown kind.</dl><H2>int <a name="ref8"></a><a name="kind">kind</a>() </H2><p> The following methods allow the specification of different mutex variable kinds. The differences are in how they are treated, not in how they function. See the next method, for a discussion on mutex kinds.</p><p></p><dl><dt><b>Returns</b>:<dd>fast for a fast mutex, and recursive for a mutex that can be locked several times by it's owner.</dl><H2>int <a name="ref9"></a><a name="kind">kind</a>(mutex_kind) </H2><p> This method, sets the mutex kind and returns the old value. The valid mutex kinds are:</p><p> <pre> mutex_kind::fast - can only be locked once, by any process. mutex_kind::recursive - can be locked multiple times, by the owner. of the original lock. it must be unlocked equally many times. mutex_kind::errorcheck - this is a fast mutex, but with simple checks that will enable the user to detect possible dedlocks. </pre></p><p></p><dl><dt><b>Parameters</b>:<dd><table width="100%" border="0"><tr><td align="left" valign="top">kind</td><td align="left" valign="top">The mutex kind, see above.</td></tr></table></dl><dl><dt><b>Returns</b>:<dd>the previous kind, prior to setting.</dl><H2>static void <a name="ref10"></a><a name="project_part">project_part</a>(const char *) </H2><p> The shared memory scheme, wants a single name to identify the overall program. It is possible, and perhaps desired that part cond/mutex/semaphore have their own name identification tree. This is possible, by stating that it should be branch of the main file name, with a give extension.</p><p> <pre> main() { mutex *ml;</p><p> pthread::set_project( "my_project" ); mutex::project_par( "mutex" ); ml = new mutex(attributes::process_shared); ... } </pre></p><p> This will set the project to my_project, and all mutexes will be derived from my_project_mutex.</p><p></p><dl><dt><b>Parameters</b>:<dd><table width="100%" border="0"><tr><td align="left" valign="top">part</td><td align="left" valign="top">A C string containing the mutex part name.</td></tr></table></dl><HR><TABLE WIDTH="100%"><TR><TD ALIGN="left" VALIGN="top"><UL><LI><I>Author</I>: Orn Hansen <oe.hansen@gamma.telenordia.se> </LI><LI>Documentation generated by oehansen@citadel on Mi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -