emacs.d/clones/www.sbcl.org/sbcl-internals/Binding-and-unbinding.html

83 lines
3.5 KiB
HTML
Raw Normal View History

2023-01-18 20:30:47 +01:00
<html lang="en">
<head>
<title>Binding and unbinding - SBCL Internals</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="SBCL Internals">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Specials.html#Specials" title="Specials">
<link rel="prev" href="Overview.html#Overview" title="Overview">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This manual is part of the SBCL software system. See the `README'
file for more information.
This manual is in the public domain and is provided with
absolutely no warranty. See the `COPYING' and `CREDITS' files for
more information.
-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Binding-and-unbinding"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="Overview.html#Overview">Overview</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Specials.html#Specials">Specials</a>
<hr>
</div>
<h3 class="section">8.2 Binding and unbinding</h3>
<p>Binding goes like this: the binding stack pointer (bsp) is bumped, old
value and symbol are stored at bsp - 1, new value is stored in
symbol's value slot or the tls.
<p>Unbinding: the symbol's value is restored from bsp - 1, value and
symbol at bsp - 1 are set to zero, and finally bsp is decremented.
<p>The <code>UNBIND-TO-HERE</code> VOP assists in unwinding the stack. It
iterates over the bindings on the binding stack until it reaches the
prescribed point. For each binding with a non-zero symbol it does an
<code>UNBIND</code>.
<p>How can a binding's symbol be zero? <code>BIND</code> is not pseudo atomic
(for performance reasons) and it can be interrupted by a signal. If
the signal hits after the bsp is incremented but before the values on
the stack are set the symbol is zero because a thread starts with a
zeroed tls plus <code>UNBIND</code> and <code>UNBIND-TO-HERE</code> both zero the
binding being unbound.
<p>Zeroing the binding's symbol would not be enough as the binding's
value can be moved or garbage collected and if the above interrupt
initiates gc (or be <code>SIG_STOP_FOR_GC</code>) it will be greeted by a
garbage pointer.
<p>Furthermore, <code>BIND</code> must always write the value to the binding
stack first and the symbol second because the symbol being non-zero
means validity to <code>UNBIND-TO-HERE</code>. For similar reasons
<code>UNBIND</code> also zeroes the symbol first. But if it is interrupted
by a signal that does an async unwind then <code>UNBIND-TO-HERE</code> can
be triggered when the symbol is zeroed but the value is not. In this
case <code>UNBIND-TO-HERE</code> must zero out the value to avoid leaving
garbage around that may wreck the ship on the next <code>BIND</code>.
<p>In other words, the invariant is that the binding stack above bsp only
contains zeros. This makes <code>BIND</code> safe in face of gc triggered at
any point during its execution.
</body></html>