1-- Starting a thread and waiting for its end on a POSIX system, through
2-- platform/posix, on the start area at the top of the thread's stack.
3
4import core/mem
5import hosted/system
6import platform/posix
7
8fixed if compiler.os <> windows then
9 -- The system's record of one started thread.
10 system_thread: type = posix.thread
11
12 -- The alignment a start area keeps, and its bytes.
13 start_alignment: () -> (bytes: usize) =
14 bytes = posix.thread_start_alignment()
15 end start_alignment
16
17 start_bytes: () -> (bytes: usize) =
18 bytes = posix.thread_start_bytes()
19 end start_bytes
20
21 -- Start a thread on `area` that runs `routine` with `argument`, or
22 -- keep the errno the system refused it with in `host`'s cell and
23 -- fail.
24 start_system_thread:
25 (host: system.host, area: []mut u8, record: ptr mut system_thread,
26 routine: posix.thread_routine, argument: usize)
27 -> none ! mem.out_of_memory =
28 posix.start_thread(area, record, routine, argument) else (problem)
29 system.record_errno(host, problem)
30 fail mem.out_of_memory
31 end
32 end start_system_thread
33
34 -- Wait for the thread `record` describes to end. A join the system
35 -- refuses is a defect of this module, since only a thread it started
36 -- is joined, and once.
37 join_system_thread: (record: ptr mut system_thread) -> none =
38 posix.join_thread(record) else (problem)
39 _ = problem
40 compiler.unreachable()
41 end
42 end join_system_thread
43end if