Current File : //usr/share/doc/python3-llfuse/html/lock.html |
<!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/html; charset=utf-8" />
<title>The global lock — Python-LLFUSE 1.3.6 documentation</title>
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '1.3.6',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="author" title="About these documents" href="about.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="top" title="Python-LLFUSE 1.3.6 documentation" href="index.html" />
<link rel="next" title="Request Handlers" href="operations.html" />
<link rel="prev" title="Data Structures" href="data.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="operations.html" title="Request Handlers"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="data.html" title="Data Structures"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Python-LLFUSE 1.3.6 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="the-global-lock">
<h1>The global lock<a class="headerlink" href="#the-global-lock" title="Permalink to this headline">¶</a></h1>
<p>Python-LLFUSE uses a global lock to synchronize concurrent requests. Since
the GIL already enforces that Python threads do not run concurrently,
this does not result in any additional performance penalties. However,
the use of an explicit lock allows direct control over which Python
thread is running at a given time.</p>
<p>Request handlers will always be called with the global lock acquired.
However, they may release the global lock for potentially time
consuming operations (like network or disk I/O), or to give other
threads a chance to run during longer computations.</p>
<p>Non-request handling threads may acquire the global lock to ensure
that the execution of a particular code block will not be interrupted
by any request handlers.</p>
<p>Obviously, any method that directly or indirectly releases the global
lock must be prepared to be called again while it has released the
lock. In addition, it (and all its callers) must not hold any prior
locks, since this may lead to deadlocks when re-acquiring the global
lock. For this reason it is crucial that every method that directly or
indirectly releases the lock is explicitly marked as such.</p>
<p>The global lock is controlled with the <a class="reference internal" href="#llfuse.lock" title="llfuse.lock"><code class="xref py py-obj docutils literal"><span class="pre">lock</span></code></a> and <a class="reference internal" href="#llfuse.lock_released" title="llfuse.lock_released"><code class="xref py py-obj docutils literal"><span class="pre">lock_released</span></code></a>
attributes of the <a class="reference internal" href="index.html#module-llfuse" title="llfuse"><code class="xref py py-obj docutils literal"><span class="pre">llfuse</span></code></a> module:</p>
<dl class="attribute">
<dt id="llfuse.lock_released">
<code class="descclassname">llfuse.</code><code class="descname">lock_released</code><a class="headerlink" href="#llfuse.lock_released" title="Permalink to this definition">¶</a></dt>
<dd><p>Controls the global lock. This object can be used as a context
manager for the <code class="docutils literal"><span class="pre">with</span></code> statement to execute a block of code
with the global lock released.</p>
</dd></dl>
<dl class="attribute">
<dt id="llfuse.lock">
<code class="descclassname">llfuse.</code><code class="descname">lock</code><a class="headerlink" href="#llfuse.lock" title="Permalink to this definition">¶</a></dt>
<dd><p>Controls the global lock. This object can be used as a context
manager for the <code class="docutils literal"><span class="pre">with</span></code> statement to execute a block of code
with the global lock acquired.</p>
<p>Note that this object resembles a <code class="docutils literal"><span class="pre">threading.Lock</span></code> instance but
is an instance of the <a class="reference internal" href="#llfuse.llfuse.Lock" title="llfuse.llfuse.Lock"><code class="xref py py-obj docutils literal"><span class="pre">llfuse.Lock</span></code></a> class which is quite different from
<code class="docutils literal"><span class="pre">threading.Lock</span></code>.</p>
</dd></dl>
<p>The <a class="reference internal" href="#llfuse.lock" title="llfuse.lock"><code class="xref py py-obj docutils literal"><span class="pre">lock</span></code></a> object has the following methods:</p>
<dl class="class">
<dt id="llfuse.llfuse.Lock">
<em class="property">class </em><code class="descclassname">llfuse.</code><code class="descname">Lock</code><a class="headerlink" href="#llfuse.llfuse.Lock" title="Permalink to this definition">¶</a></dt>
<dd><dl class="method">
<dt id="llfuse.llfuse.Lock.Lock.acquire">
<code class="descclassname">Lock.</code><code class="descname">acquire</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#llfuse.llfuse.Lock.Lock.acquire" title="Permalink to this definition">¶</a></dt>
<dd><p>Lock.acquire(self, timeout=None)
Acquire global lock</p>
<blockquote>
<div>If <em>timeout</em> is not None, and the lock could not be acquired
after waiting for <em>timeout</em> seconds, return False. Otherwise
return True.</div></blockquote>
</dd></dl>
<dl class="method">
<dt id="llfuse.llfuse.Lock.Lock.release">
<code class="descclassname">Lock.</code><code class="descname">release</code><span class="sig-paren">(</span><em>self</em><span class="sig-paren">)</span><a class="headerlink" href="#llfuse.llfuse.Lock.Lock.release" title="Permalink to this definition">¶</a></dt>
<dd><p>Release global lock</p>
</dd></dl>
<dl class="method">
<dt id="llfuse.llfuse.Lock.Lock.yield_">
<code class="descclassname">Lock.</code><code class="descname">yield_</code><span class="sig-paren">(</span><em>self</em>, <em>count=1</em><span class="sig-paren">)</span><a class="headerlink" href="#llfuse.llfuse.Lock.Lock.yield_" title="Permalink to this definition">¶</a></dt>
<dd><p>Yield global lock to a different thread</p>
<p>A call to <a class="reference internal" href="#llfuse.llfuse.Lock.Lock.yield_" title="llfuse.llfuse.Lock.Lock.yield_"><code class="xref py py-obj docutils literal"><span class="pre">yield_</span></code></a> is roughly similar to:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">count</span><span class="p">):</span>
<span class="k">if</span> <span class="n">no_threads_waiting_for</span><span class="p">(</span><span class="n">lock</span><span class="p">):</span>
<span class="k">break</span>
<span class="n">lock</span><span class="o">.</span><span class="n">release</span><span class="p">()</span>
<span class="n">lock</span><span class="o">.</span><span class="n">acquire</span><span class="p">()</span>
</pre></div>
</div>
<p>However, when using <a class="reference internal" href="#llfuse.llfuse.Lock.Lock.yield_" title="llfuse.llfuse.Lock.Lock.yield_"><code class="xref py py-obj docutils literal"><span class="pre">yield_</span></code></a> it is guaranteed that the lock will
actually be passed to a different thread (the above pseude-code may
result in the same thread re-acquiring the lock <em>count</em> times).</p>
</dd></dl>
</dd></dl>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper"><h3><a href="index.html">Table Of Contents</a></h3>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="about.html">About</a></li>
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="general.html">General Information</a></li>
<li class="toctree-l1"><a class="reference internal" href="fuse_api.html">FUSE API Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="data.html">Data Structures</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">The global lock</a></li>
<li class="toctree-l1"><a class="reference internal" href="operations.html">Request Handlers</a></li>
<li class="toctree-l1"><a class="reference internal" href="util.html">Utility Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="gotchas.html">Common Gotchas</a></li>
<li class="toctree-l1"><a class="reference internal" href="example.html">Example File Systems</a></li>
<li class="toctree-l1"><a class="reference internal" href="changes.html">Changelog</a></li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="data.html"
title="previous chapter">Data Structures</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="operations.html"
title="next chapter">Request Handlers</a></p>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="operations.html" title="Request Handlers"
>next</a> |</li>
<li class="right" >
<a href="data.html" title="Data Structures"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Python-LLFUSE 1.3.6 documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2010-2015, Nikolaus Rath.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.9.
</div>
</body>
</html>