source: project/chicken/trunk/manual/Unit srfi-18 @ 13683

Last change on this file since 13683 was 13683, checked in by felix winkelmann, 12 years ago

slight manual fixes; wiki2html improvements

File size: 3.7 KB
Line 
1[[tags: manual]]
2
3[[toc:]]
4
5== Unit srfi-18
6
7A simple multithreading package. This threading package follows largely
8the specification of SRFI-18. For more information see the documentation
9for [[http://srfi.schemers.org/srfi-18/srfi-18.html|SRFI-18]].
10
11'''Notes:'''
12
13* {{thread-start!}} accepts a thunk (a zero argument procedure) as argument, which is equivalent to {{(thread-start! (make-thread THUNK))}}.
14
15* {{thread-sleep!}} accepts a seconds real number value in addition to a time object.
16
17* When an uncaught exception (i.e. an error) is signalled in a thread other than the primordial thread and warnings are enabled (see: {{enable-warnings}}, then a warning message is written to the port that is the value of {{(current-error-port)}}.
18
19* Blocking I/O will block all threads, except for some socket operations (see the section about the {{tcp}} unit). An exception is the read-eval-print loop on UNIX platforms: waiting for input will not block other threads, provided the current input port reads input from a console.
20
21* It is generally not a good idea for one thread to call a continuation created by another thread, if {{dynamic-wind}} is involved.
22
23* When more than one thread compete for the current time-slice, the thread that was waiting first will become the next runnable thread.
24
25* The dynamic environment of a thread consists of the following state:
26
27** The current input-, output- and error-port
28
29** The current exception handler
30
31** The values of all current parameters (created by {{make-parameter}})
32
33** Any pending {{dynamic-wind}} thunks.
34
35* When an error is triggered inside the execution context of a thread, the default exception-handler will simply terminate the thread (and store the error condition for later use). Pending {{dynamic-wind}} thunks will ''not'' be invoked. Use a custom exception handler for the thread in that case.
36
37The following procedures are provided, in addition to the procedures defined in SRFI-18:
38
39
40
41=== thread-signal!
42
43 [procedure] (thread-signal! THREAD X)
44
45This will cause {{THREAD}} to signal the condition {{X}} once it is scheduled
46for execution. After signalling the condition, the thread continues with its normal
47execution.
48
49=== thread-quantum
50
51 [procedure] (thread-quantum THREAD)
52
53Returns the quantum of {{THREAD}}, which is an exact integer
54specifying the approximate time-slice of the thread in milliseconds.
55
56=== thread-quantum-set!
57
58 [procedure] (thread-quantum-set! THREAD QUANTUM)
59
60Sets the quantum of {{THREAD}} to {{QUANTUM}}.
61
62=== thread-suspend!
63
64 [procedure] (thread-suspend! THREAD)
65
66Suspends the execution of {{THREAD}} until resumed.
67
68=== thread-resume!
69
70 [procedure] (thread-resume! THREAD)
71
72Readies the suspended thread {{THREAD}}.
73
74=== thread-wait-for-i/o!
75
76 [procedure] (thread-wait-for-i/o! FD [MODE])
77
78Suspends the current thread until input ({{MODE}} is {{#:input}}), output ({{MODE}} is {{#:output}})
79or both ({{MODE}} is {{#:all}}) is available. {{FD}} should be a file-descriptor (not a port!) open
80for input or output, respectively.
81
82=== time->milliseconds
83
84 [procedure] (time->milliseconds TIME)
85
86Converts a time object (as created via {{current-time}}) into an exact integer representing
87the number of milliseconds since process startup.
88
89=== milliseconds->time
90
91 [procedure] (milliseconds->time ms)
92
93Converts into a time object an exact integer representing
94the number of milliseconds since process startup.
95
96This procedure may be useful in combination with {{thread-sleep!}} when your compilation unit is using {{(declare fixnum-arithmetic)}}.  In that case you won't be able to pass an inexact value to {{thread-sleep!}}, but you can do the following:
97
98 (define (thread-sleep!/ms ms)
99   (thread-sleep!
100    (milliseconds->time (+ ms (current-milliseconds)))))
101
102---
103Previous: [[Unit regex]]
104
105Next: [[Unit posix]]
Note: See TracBrowser for help on using the repository browser.