<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Constructs a new SyncMutex object</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="class.syncmutex.html">SyncMutex</a></div> <div class="next" style="text-align: right; float: right;"><a href="syncmutex.lock.html">SyncMutex::lock</a></div> <div class="up"><a href="class.syncmutex.html">SyncMutex</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="syncmutex.construct" class="refentry"> <div class="refnamediv"> <h1 class="refname">SyncMutex::__construct</h1> <p class="verinfo">(PECL sync >= 1.0.0)</p><p class="refpurpose"><span class="refname">SyncMutex::__construct</span> — <span class="dc-title">Constructs a new SyncMutex object</span></p> </div> <div class="refsect1 description" id="refsect1-syncmutex.construct-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="methodname"><strong>SyncMutex::__construct</strong></span> ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span> ] )</div> <p class="para rdfs-comment"> Constructs a named or unnamed countable mutex. </p> </div> <div class="refsect1 parameters" id="refsect1-syncmutex.construct-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <code class="parameter">name</code></dt> <dd> <p class="para"> The name of the mutex if this is a named mutex object. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> If the name already exists, it must be able to be opened by the current user that the process is running as or an exception will be thrown with a meaningless error message. </p> </p></blockquote> </dd> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-syncmutex.construct-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The new SyncMutex object. An exception is thrown if the mutex cannot be created or opened. </p> </div> <div class="refsect1 examples" id="refsect1-syncmutex.construct-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-4590"> <p><strong>Example #1 <span class="function"><strong>SyncMutex::__construct()</strong></span> named mutex with lock timeout example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$mutex </span><span style="color: #007700">= new </span><span style="color: #0000BB">SyncMutex</span><span style="color: #007700">(</span><span style="color: #DD0000">"UniqueName"</span><span style="color: #007700">);<br /><br />if (!</span><span style="color: #0000BB">$mutex</span><span style="color: #007700">-></span><span style="color: #0000BB">lock</span><span style="color: #007700">(</span><span style="color: #0000BB">3000</span><span style="color: #007700">))<br />{<br /> echo </span><span style="color: #DD0000">"Unable to lock mutex."</span><span style="color: #007700">;<br /><br /> exit();<br />}<br /><br /></span><span style="color: #FF8000">/* ... */<br /><br /></span><span style="color: #0000BB">$mutex</span><span style="color: #007700">-></span><span style="color: #0000BB">unlock</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <div class="example" id="example-4591"> <p><strong>Example #2 <span class="function"><strong>SyncMutex::__construct()</strong></span> unnamed mutex example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$mutex </span><span style="color: #007700">= new </span><span style="color: #0000BB">SyncMutex</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$mutex</span><span style="color: #007700">-></span><span style="color: #0000BB">lock</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/* ... */<br /><br /></span><span style="color: #0000BB">$mutex</span><span style="color: #007700">-></span><span style="color: #0000BB">unlock</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </div> <div class="refsect1 seealso" id="refsect1-syncmutex.construct-seealso"> <h3 class="title">See Also</h3> <ul class="simplelist"> <li class="member"><span class="methodname"><a href="syncmutex.lock.html" class="methodname" rel="rdfs-seeAlso">SyncMutex::lock()</a> - Waits for an exclusive lock</span></li> <li class="member"><span class="methodname"><a href="syncmutex.unlock.html" class="methodname" rel="rdfs-seeAlso">SyncMutex::unlock()</a> - Unlocks the mutex</span></li> </ul> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="class.syncmutex.html">SyncMutex</a></div> <div class="next" style="text-align: right; float: right;"><a href="syncmutex.lock.html">SyncMutex::lock</a></div> <div class="up"><a href="class.syncmutex.html">SyncMutex</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>