File: MLtonSignal

package info (click to toggle)
mlton 20061107-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 27,828 kB
  • ctags: 61,118
  • sloc: ansic: 11,446; makefile: 1,339; sh: 1,160; lisp: 900; pascal: 256; asm: 97
file content (450 lines) | stat: -rw-r--r-- 12,678 bytes parent folder | download
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta name="robots" content="index,nofollow">



<title>MLtonSignal - MLton Standard ML Compiler (SML Compiler)</title>
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="all" href="common.css">
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="screen" href="screen.css">
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="print" href="print.css">


<link rel="Start" href="Home">


</head>

<body lang="en" dir="ltr">

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-833377-1";
urchinTracker();
</script>
<table bgcolor = lightblue cellspacing = 0 style = "border: 0px;" width = 100%>
  <tr>
    <td style = "
		border: 0px;
		color: darkblue; 
		font-size: 150%;
		text-align: left;">
      <a class = mltona href="Home">MLton 20061025</a>
    <td style = "
		border: 0px;
		font-size: 150%;
		text-align: center;
		width: 50%;">
      MLtonSignal
    <td style = "
		border: 0px;
		text-align: right;">
      <table cellspacing = 0 style = "border: 0px">
        <tr style = "vertical-align: middle;">
      </table>
  <tr style = "background-color: white;">
    <td colspan = 3
	style = "
		border: 0px;
		font-size:70%;
		text-align: right;">
      <a href = "Home">Home</a>
      &nbsp;<a href = "Index">Index</a>
      &nbsp;
</table>
<div id="content" lang="en" dir="ltr">

<pre class=code>
<B><FONT COLOR="#5F9EA0">signature</FONT></B> MLTON_SIGNAL <B><FONT COLOR="#5F9EA0">=</FONT></B>
   <B><FONT COLOR="#5F9EA0">sig</FONT></B>
      <B><FONT COLOR="#A020F0">type</FONT></B> t
      <B><FONT COLOR="#A020F0">type</FONT></B> signal <B><FONT COLOR="#5F9EA0">=</FONT></B> t

      <B><FONT COLOR="#5F9EA0">structure</FONT></B> Handler:
         <B><FONT COLOR="#5F9EA0">sig</FONT></B>
            <B><FONT COLOR="#A020F0">type</FONT></B> t

            <B><FONT COLOR="#A020F0">val</FONT></B> default: t
            <B><FONT COLOR="#A020F0">val</FONT></B> handler: (Thread.Runnable.t <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> Thread.Runnable.t) <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> t
            <B><FONT COLOR="#A020F0">val</FONT></B> ignore: t
            <B><FONT COLOR="#A020F0">val</FONT></B> isDefault: t <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> <B><FONT COLOR="#228B22">bool</FONT></B>
            <B><FONT COLOR="#A020F0">val</FONT></B> isIgnore: t <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> <B><FONT COLOR="#228B22">bool</FONT></B>
            <B><FONT COLOR="#A020F0">val</FONT></B> simple: (<B><FONT COLOR="#228B22">unit</FONT></B> <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> <B><FONT COLOR="#228B22">unit</FONT></B>) <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> t
         <B><FONT COLOR="#A020F0">end</FONT></B>

      <B><FONT COLOR="#5F9EA0">structure</FONT></B> Mask:
         <B><FONT COLOR="#5F9EA0">sig</FONT></B>
            <B><FONT COLOR="#A020F0">type</FONT></B> t
               
            <B><FONT COLOR="#A020F0">val</FONT></B> all: t
            <B><FONT COLOR="#A020F0">val</FONT></B> allBut: signal <B><FONT COLOR="#228B22">list</FONT></B> <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> t
            <B><FONT COLOR="#A020F0">val</FONT></B> block: t <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> <B><FONT COLOR="#228B22">unit</FONT></B>
            <B><FONT COLOR="#A020F0">val</FONT></B> getBlocked: <B><FONT COLOR="#228B22">unit</FONT></B> <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> t
            <B><FONT COLOR="#A020F0">val</FONT></B> isMember: t <B><FONT COLOR="#5F9EA0">*</FONT></B> signal <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> <B><FONT COLOR="#228B22">bool</FONT></B>
            <B><FONT COLOR="#A020F0">val</FONT></B> none: t
            <B><FONT COLOR="#A020F0">val</FONT></B> setBlocked: t <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> <B><FONT COLOR="#228B22">unit</FONT></B>
            <B><FONT COLOR="#A020F0">val</FONT></B> some: signal <B><FONT COLOR="#228B22">list</FONT></B> <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> t
            <B><FONT COLOR="#A020F0">val</FONT></B> unblock: t <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> <B><FONT COLOR="#228B22">unit</FONT></B>
         <B><FONT COLOR="#A020F0">end</FONT></B>

      <B><FONT COLOR="#A020F0">val</FONT></B> getHandler: t <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> Handler.t
      <B><FONT COLOR="#A020F0">val</FONT></B> handled: <B><FONT COLOR="#228B22">unit</FONT></B> <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> Mask.t
      <B><FONT COLOR="#A020F0">val</FONT></B> prof: t
      <B><FONT COLOR="#A020F0">val</FONT></B> restart: <B><FONT COLOR="#228B22">bool</FONT></B> <B><FONT COLOR="#A020F0">ref</FONT></B>
      <B><FONT COLOR="#A020F0">val</FONT></B> setHandler: t <B><FONT COLOR="#5F9EA0">*</FONT></B> Handler.t <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> <B><FONT COLOR="#228B22">unit</FONT></B>
      <B><FONT COLOR="#A020F0">val</FONT></B> suspend: Mask.t <B><FONT COLOR="#5F9EA0">-</FONT></B><B><FONT COLOR="#5F9EA0">&gt;</FONT></B> <B><FONT COLOR="#228B22">unit</FONT></B>
      <B><FONT COLOR="#A020F0">val</FONT></B> vtalrm: t
   <B><FONT COLOR="#A020F0">end</FONT></B>
</PRE>
<p>
 
</p>
<p>
Signals handlers are functions from (runnable) threads to (runnable) threads.  When a signal arrives, the corresponding signal handler is invoked, its argument being the thread that was interrupted by the signal.  The signal handler runs asynchronously, in its own thread. The signal handler returns the thread that it would like to resume execution (this is often the thread that it was passed).  It is an error for a signal handler to raise an exception that is not handled within the signal handler itself. 
</p>
<p>
A signal handler is never invoked while the running thread is in a critical section (see <a href="MLtonThread">MLtonThread</a>).  Invoking a signal handler implicitly enters a critical section and the normal return of a signal handler implicitly exits the critical section; hence, a signal handler is never interrupted by another signal handler. 
</p>

    <ul>

    <li>
<p>
 <tt>type&nbsp;t</tt> 
</p>
</li>

        <ul>

  the type of signals. 
        </ul>


    <li class="gap">
<p>
 <tt>type&nbsp;Handler.t</tt> 
</p>
</li>

        <ul>

  the type of signal handlers. 
        </ul>


    <li class="gap">
<p>
 <tt>Handler.default</tt> 
</p>
</li>

        <ul>

  handles the signal with the default action. 
        </ul>


    <li class="gap">
<p>
 <tt>Handler.handler&nbsp;f</tt> 
</p>
</li>

        <ul>

  returns a handler <tt>h</tt> such that when a signal <tt>s</tt> is handled   by <tt>h</tt>, <tt>f</tt> will be passed the thread that was interrupted by   <tt>s</tt> and should return the thread that will resume execution. 
        </ul>


    <li class="gap">
<p>
 <tt>Handler.ignore</tt> 
</p>
</li>

        <ul>

  is a handler that will ignore the signal. 
        </ul>


    <li class="gap">
<p>
 <tt>Handler.isDefault</tt> 
</p>
</li>

        <ul>

  returns true if the handler is the default handler. 
        </ul>


    <li class="gap">
<p>
 <tt>Handler.isIgnore</tt> 
</p>
</li>

        <ul>

  returns true if the handler is the ignore handler. 
        </ul>


    <li class="gap">
<p>
 <tt>Handler.simple&nbsp;f</tt> 
</p>
</li>

        <ul>

  returns a handler that executes <tt>f&nbsp;()</tt> and does not switch   threads. 
        </ul>


    <li class="gap">
<p>
 <tt>type&nbsp;Mask.t</tt> 
</p>
</li>

        <ul>

  the type of signal masks, which are sets of blocked signals. 
        </ul>


    <li class="gap">
<p>
 <tt>Mask.all</tt> 
</p>
</li>

        <ul>

  a mask of all signals. 
        </ul>


    <li class="gap">
<p>
 <tt>Mask.allBut&nbsp;l</tt> 
</p>
</li>

        <ul>

  a mask of all signals except for those in <tt>l</tt>. 
        </ul>


    <li class="gap">
<p>
 <tt>Mask.block&nbsp;m</tt> 
</p>
</li>

        <ul>

  blocks all signals in <tt>m</tt>. 
        </ul>


    <li class="gap">
<p>
 <tt>Mask.getBlocked&nbsp;()</tt> 
</p>
</li>

        <ul>

  gets the signal mask <tt>m</tt>, i.e. a signal is blocked if and only   if it is in <tt>m</tt>. 
        </ul>


    <li class="gap">
<p>
 <tt>Mask.isMember&nbsp;(m,&nbsp;s)</tt> 
</p>
</li>

        <ul>

  returns true if the signal <tt>s</tt> is in <tt>m</tt>. 
        </ul>


    <li class="gap">
<p>
 <tt>Mask.none</tt> 
</p>
</li>

        <ul>

  a mask of no signals. 
        </ul>


    <li class="gap">
<p>
 <tt>Mask.setBlocked&nbsp;m</tt> 
</p>
</li>

        <ul>

  sets the signal mask to <tt>m</tt>, i.e. a signal is blocked if and only   if it is in <tt>m</tt>. 
        </ul>


    <li class="gap">
<p>
 <tt>Mask.some&nbsp;l</tt> 
</p>
</li>

        <ul>

  a mask of the signals in <tt>l</tt>. 
        </ul>


    <li class="gap">
<p>
 <tt>Mask.unblock&nbsp;m</tt> 
</p>
</li>

        <ul>

  unblocks all signals in <tt>m</tt>. 
        </ul>


    <li class="gap">
<p>
 <tt>getHandler&nbsp;s</tt> 
</p>
</li>

        <ul>

  returns the current handler for signal <tt>s</tt>. 
        </ul>


    <li class="gap">
<p>
 <tt>handled&nbsp;()</tt> 
</p>
</li>

        <ul>

  returns the signal mask <tt>m</tt> corresponding to the currently handled   signals; i.e., a signal is handled if and only if it is in <tt>m</tt>. 
        </ul>


    <li class="gap">
<p>
 <tt>prof</tt> 
</p>
</li>

        <ul>

  <tt>SIGPROF</tt>, the profiling signal. 
        </ul>


    <li class="gap">
<p>
 <tt>restart</tt> 
</p>
</li>

        <ul>

  dynamically determines the behavior of interrupted system calls; when   <tt>true</tt>, interrupted system calls are restarted; when <tt>false</tt>,   interrupted system calls raise <tt>OS.SysError</tt>. 
        </ul>


    <li class="gap">
<p>
 <tt>setHandler&nbsp;(s,&nbsp;h)</tt> 
</p>
</li>

        <ul>

  sets the handler for signal <tt>s</tt> to <tt>h</tt>. 
        </ul>


    <li class="gap">
<p>
 <tt>suspend&nbsp;m</tt> 
</p>
</li>

        <ul>

  temporarily sets the signal mask to <tt>m</tt> and suspends until an   unmasked signal is received and handled, at which point   <tt>suspend</tt> resets the mask and returns. 
        </ul>


    <li class="gap">
<p>
 <tt>vtalrm</tt> 
</p>
</li>

        <ul>

  <tt>SIGVTALRM</tt>, the signal for virtual timers. 
        </ul>



    </ul>


<h2 id="head-f8a475209a6f55001051eae0624aca8b3a75b651">Interruptible System Calls</h2>
<p>
Signal handling interacts in a non-trivial way with those functions in the <a href="BasisLibrary">Basis Library</a> that correspond directly to interruptible system calls (a subset of those functions that may raise <tt>OS.SysError</tt>).  The desire is that these functions should have predictable semantics.  The principal concerns are: 
</p>

    <ol type="1">

    <li>
<p>
System calls that are interrupted by signals should, by default, be  restarted; the alternative is to raise   
<pre> OS.SysError (Posix.Error.errorMsg Posix.Error.intr, 
              SOME Posix.Error.intr)</pre> This behavior is determined dynamically by the value of <tt>Signal.restart</tt>. 
</p>
</li>
    <li class="gap">
<p>
Signal handlers should always get a chance to run (when outside a  critical region).  If a system call is interrupted by a signal, then  the signal handler will run before the call is restarted or  <tt>OS.SysError</tt> is raised; that is, before the <tt>Signal.restart</tt>  check. 
</p>
</li>
    <li class="gap">
<p>
A system call that must be restarted while in a critical section  will be restarted with the handled signals blocked (and the previously  blocked signals remembered).  This encourages the system call to  complete, allowing the program to make progress towards leaving the  critical section where the signal can be handled.  If the system call  completes, the set of blocked signals are restored to those previously  blocked. 
</p>
</li>
</ol>

</div>



<p>
<hr>
Last edited on 2005-12-02 04:22:43 by <span title="ppp-71-139-183-221.dsl.snfc21.pacbell.net"><a href="StephenWeeks">StephenWeeks</a></span>.
</body></html>