<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.9.1"/>
<title>V8 API Reference Guide for node.js v0.4.1: v8::Unlocker Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">V8 API Reference Guide for node.js v0.4.1
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.9.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="namespacev8.html">v8</a></li><li class="navelem"><a class="el" href="classv8_1_1_unlocker.html">Unlocker</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="classv8_1_1_unlocker-members.html">List of all members</a>  </div>
  <div class="headertitle">
<div class="title">v8::Unlocker Class Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p><code>#include &lt;<a class="el" href="v8_8h_source.html">v8.h</a>&gt;</code></p>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Multiple threads in <a class="el" href="classv8_1_1_v8.html">V8</a> are allowed, but only one thread at a time is allowed to use <a class="el" href="classv8_1_1_v8.html">V8</a>. The definition of 'using <a class="el" href="classv8_1_1_v8.html">V8</a>' includes accessing handles or holding onto object pointers obtained from <a class="el" href="classv8_1_1_v8.html">V8</a> handles. It is up to the user of <a class="el" href="classv8_1_1_v8.html">V8</a> to ensure (perhaps with locking) that this constraint is not violated.</p>
<p>If you wish to start using <a class="el" href="classv8_1_1_v8.html">V8</a> in a thread you can do this by constructing a <a class="el" href="classv8_1_1_locker.html">v8::Locker</a> object. After the code using <a class="el" href="classv8_1_1_v8.html">V8</a> has completed for the current thread you can call the destructor. This can be combined with C++ scope-based construction as follows:</p>
<div class="fragment"><div class="line">...</div>
<div class="line">{</div>
<div class="line">  <a class="code" href="classv8_1_1_locker.html">v8::Locker</a> locker;</div>
<div class="line">  ...</div>
<div class="line">  <span class="comment">// Code using V8 goes here.</span></div>
<div class="line">  ...</div>
<div class="line">} <span class="comment">// Destructor called here</span></div>
</div><!-- fragment --><p>If you wish to stop using <a class="el" href="classv8_1_1_v8.html">V8</a> in a thread A you can do this by either by destroying the <a class="el" href="classv8_1_1_locker.html">v8::Locker</a> object as above or by constructing a <a class="el" href="classv8_1_1_unlocker.html">v8::Unlocker</a> object:</p>
<div class="fragment"><div class="line">{</div>
<div class="line">  <a class="code" href="classv8_1_1_unlocker.html">v8::Unlocker</a> unlocker;</div>
<div class="line">  ...</div>
<div class="line">  <span class="comment">// Code not using V8 goes here while V8 can run in another thread.</span></div>
<div class="line">  ...</div>
<div class="line">} <span class="comment">// Destructor called here.</span></div>
</div><!-- fragment --><p>The <a class="el" href="classv8_1_1_unlocker.html">Unlocker</a> object is intended for use in a long-running callback from <a class="el" href="classv8_1_1_v8.html">V8</a>, where you want to release the <a class="el" href="classv8_1_1_v8.html">V8</a> lock for other threads to use.</p>
<p>The <a class="el" href="classv8_1_1_locker.html">v8::Locker</a> is a recursive lock. That is, you can lock more than once in a given thread. This can be useful if you have code that can be called either from code that holds the lock or from code that does not. The <a class="el" href="classv8_1_1_unlocker.html">Unlocker</a> is not recursive so you can not have several Unlockers on the stack at once, and you can not use an <a class="el" href="classv8_1_1_unlocker.html">Unlocker</a> in a thread that is not inside a <a class="el" href="classv8_1_1_locker.html">Locker</a>'s scope.</p>
<p>An unlocker will unlock several lockers if it has to and reinstate the correct depth of locking on its destruction. eg.:</p>
<div class="fragment"><div class="line"><span class="comment">// V8 not locked.</span></div>
<div class="line">{</div>
<div class="line">  <a class="code" href="classv8_1_1_locker.html">v8::Locker</a> locker;</div>
<div class="line">  <span class="comment">// V8 locked.</span></div>
<div class="line">  {</div>
<div class="line">    <a class="code" href="classv8_1_1_locker.html">v8::Locker</a> another_locker;</div>
<div class="line">    <span class="comment">// V8 still locked (2 levels).</span></div>
<div class="line">    {</div>
<div class="line">      <a class="code" href="classv8_1_1_unlocker.html">v8::Unlocker</a> unlocker;</div>
<div class="line">      <span class="comment">// V8 not locked.</span></div>
<div class="line">    }</div>
<div class="line">    <span class="comment">// V8 locked again (2 levels).</span></div>
<div class="line">  }</div>
<div class="line">  <span class="comment">// V8 still locked (1 level).</span></div>
<div class="line">}</div>
<div class="line"><span class="comment">// V8 Now no longer locked.</span></div>
</div><!-- fragment --> </div><hr/>The documentation for this class was generated from the following file:<ul>
<li>deps/v8/include/<a class="el" href="v8_8h_source.html">v8.h</a></li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Aug 11 2015 23:46:56 for V8 API Reference Guide for node.js v0.4.1 by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.9.1
</small></address>
</body>
</html>
