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

Last change on this file since 10003 was 10003, checked in by Kon Lovett, 11 years ago

Added unit srfi-69. Removed SRFI 69 items from unit extras. Removed SRFI 69 dep by compiler & eval. Bumped version since this is a serious change.

File size: 2.9 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
35The following procedures are provided, in addition to the procedures defined in SRFI-18:
36
37
38
39=== thread-signal!
40
41 [procedure] (thread-signal! THREAD X)
42
43This will cause {{THREAD}} to signal the condition {{X}} once it is scheduled
44for execution. After signalling the condition, the thread continues with its normal
45execution.
46
47=== thread-quantum
48
49 [procedure] (thread-quantum THREAD)
50
51Returns the quantum of {{THREAD}}, which is an exact integer
52specifying the approximate time-slice of the thread in milliseconds.
53
54=== thread-quantum-set!
55
56 [procedure] (thread-quantum-set! THREAD QUANTUM)
57
58Sets the quantum of {{THREAD}} to {{QUANTUM}}.
59
60=== thread-suspend!
61
62 [procedure] (thread-suspend! THREAD)
63
64Suspends the execution of {{THREAD}} until resumed.
65
66=== thread-resume!
67
68 [procedure] (thread-resume! THREAD)
69
70Readies the suspended thread {{THREAD}}.
71
72=== thread-wait-for-i/o!
73
74 [procedure] (thread-wait-for-i/o! FD [MODE])
75
76Suspends the current thread until input ({{MODE}} is {{#:input}}), output ({{MODE}} is {{#:output}})
77or both ({{MODE}} is {{#:all}}) is available. {{FD}} should be a file-descriptor (not a port!) open
78for input or output, respectively.
79
80=== time->milliseconds
81
82 [procedure] (time->milliseconds TIME)
83
84Converts a time object (as created via {{current-time}}) into an exact integer representing
85the number of milliseconds since process startup.
86
87
88Previous: [[Unit regex]]
89
90Next: [[Unit srfi-69]]
Note: See TracBrowser for help on using the repository browser.