This file is indexed.

/usr/share/doc/sbcl/sbcl-internals/Programming-with-signal-handling-in-mind.html is in sbcl-doc 2:1.4.5-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- 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. -->
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Programming with signal handling in mind (SBCL Internals)</title>

<meta name="description" content="Programming with signal handling in mind (SBCL Internals)">
<meta name="keywords" content="Programming with signal handling in mind (SBCL Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html#Top" rel="start" title="Top">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Signal-handling.html#Signal-handling" rel="up" title="Signal handling">
<link href="Slot_002dValue.html#Slot_002dValue" rel="next" title="Slot-Value">
<link href="Implementation-warts.html#Implementation-warts" rel="prev" title="Implementation warts">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en">
<a name="Programming-with-signal-handling-in-mind"></a>
<div class="header">
<p>
Previous: <a href="Implementation-warts.html#Implementation-warts" accesskey="p" rel="prev">Implementation warts</a>, Up: <a href="Signal-handling.html#Signal-handling" accesskey="u" rel="up">Signal handling</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<hr>
<a name="Programming-with-signal-handling-in-mind-1"></a>
<h3 class="section">7.4 Programming with signal handling in mind</h3>

<a name="On-reentrancy"></a>
<h4 class="subsection">7.4.1 On reentrancy</h4>

<p>Since they might be invoked in the middle of just about anything,
signal handlers must invoke only reentrant functions or async signal
safe functions to be more precise. Functions passed to
<code>INTERRUPT-THREAD</code> have the same restrictions and considerations
as signal handlers.
</p>
<p>Destructive modification, and holding mutexes to protect destructive
modifications from interfering with each other are often the cause of
non-reentrancy. Recursive locks are not likely to help, and while
<code>WITHOUT-INTERRUPTS</code> is, it is considered untrendy to litter the
code with it.
</p>
<p>Some basic functionality, such as streams and the debugger are
intended to be reentrant, but not much effort has been spent on
verifying it.
</p>
<a name="More-deadlocks"></a>
<h4 class="subsection">7.4.2 More deadlocks</h4>

<p>If functions A and B directly or indirectly lock mutexes M and N, they
should do so in the same order to avoid deadlocks.
</p>
<p>A less trivial scenario is where there is only one lock involved but
it is acquired in a <code>WITHOUT-GCING</code> in thread A, and outside of
<code>WITHOUT-GCING</code> in thread B. If thread A has entered
<code>WITHOUT-GCING</code> but thread B has the lock when the gc hits, then
A cannot leave <code>WITHOUT-GCING</code> because it is waiting for the lock
the already suspended thread B has. From this scenario one can easily
derive the rule: in a <code>WITHOUT-GCING</code> form (or pseudo atomic for
that matter) never wait for another thread that&rsquo;s not in
<code>WITHOUT-GCING</code>.
</p>
<p>Somewhat of a special case, it is enforced by the runtime that
<code>SIG_STOP_FOR_GC</code> and <code>SIG_RESUME_FROM_GC</code> always unblocked
when we might trigger a gc (i.e. on alloc or calling into Lisp).
</p>
<a name="Calling-user-code"></a>
<h4 class="subsection">7.4.3 Calling user code</h4>

<p>For the reasons above, calling user code, i.e. functions passed in, or
in other words code that one cannot reason about, from non-reentrant
code (holding locks), <code>WITHOUT-INTERRUPTS</code>, <code>WITHOUT-GCING</code>
is dangerous and best avoided.
</p>
<a name="Debugging"></a>
<h3 class="section">7.5 Debugging</h3>

<p>It is not easy to debug signal problems. The best bet probably is to
enable <code>QSHOW</code> and <code>QSHOW_SIGNALS</code> in runtime.h and once
SBCL runs into problems attach gdb. A simple <code>thread apply all
ba</code> is already tremendously useful. Another possibility is to send a
SIGABRT to SBCL to provoke landing in LDB, if it&rsquo;s compiled with it
and it has not yet done so on its own.
</p>
<p>Note, that fprintf used by QSHOW is not reentrant and at least on x86
linux it is known to cause deadlocks, so place SHOW and co carefully,
ideally to places where blockable signals are blocked. Use
<code>QSHOW_SAFE</code> if you like.
</p><hr>
<div class="header">
<p>
Previous: <a href="Implementation-warts.html#Implementation-warts" accesskey="p" rel="prev">Implementation warts</a>, Up: <a href="Signal-handling.html#Signal-handling" accesskey="u" rel="up">Signal handling</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>



</body>
</html>