Lines Matching refs:thread
17 ;; `run-yield-to-suspended`: Yields twice to a spawned thread, first with an uncancellable yield, t…
18 ;; A complication is that we can't guarantee that if the spawned thread yields, the supertask …
19 ;; cancel the subtask before the subtask's implicit thread is rescheduled. To handle this, the…
20 ;; thread first waits on a future to be written by the supertask, then yields to the spawned t…
23 ;; thread in the same subtask to explicitly wake it up. This is done by the subtask spawning a…
24 ;; waits on a future to be written by the supertask, and then resumes the main thread once tha…
25 ;; After setting up this thread, `run-suspend` performs an uncancellable suspend, then a cance…
26 …aller cancels the subtask during the first suspend, writes to the future to make the spawned thread
27 ;; resume the implicit thread, and ensures that the cancellation only takes effect on the seco…
29 …d-to-suspended`: Similar to `run-suspend`, but uses `thread.suspend-to-suspended` instead of `thre…
43 ;; Defines the table for the thread start functions, of which there are two
49 … (import "" "thread.new-indirect" (func $thread-new-indirect (param i32 i32) (result i32)))
50 (import "" "thread.suspend" (func $thread-suspend (result i32)))
51 (import "" "thread.suspend-cancellable" (func $thread-suspend-cancellable (result i32)))
52 … (import "" "thread.yield-to-suspended" (func $thread-yield-to-suspended (param i32) (result i32)))
53 …(import "" "thread.yield-to-suspended-cancellable" (func $thread-yield-to-suspended-cancellable (p…
54 …(import "" "thread.suspend-to-suspended" (func $thread-suspend-to-suspended (param i32) (result i3…
55 …(import "" "thread.suspend-to-suspended-cancellable" (func $thread-suspend-to-suspended-cancellabl…
56 (import "" "thread.yield" (func $thread-yield (result i32)))
57 (import "" "thread.yield-cancellable" (func $thread-yield-cancellable (result i32)))
58 (import "" "thread.index" (func $thread-index (result i32)))
59 (import "" "thread.unsuspend" (func $thread-unsuspend (param i32)))
66 ;; Indices into the function table for the thread start functions
73 (if (i32.ne (call $thread-yield) (i32.const 0)) (then unreachable))
75 (if (i32.ne (call $thread-yield-cancellable) (i32.const 1)) (then unreachable))
88 ;; Extract the thread index and future to wait on from the argument structure
89 (local $thread-index i32) (local $future i32)
90 (local.set $thread-index (i32.load offset=0 (local.get 0)))
93 ;; Wait for the supertask to signal us to wake up suspended thread.
95 ;; Resume the main thread, which is suspended in an uncancellable suspend
96 (call $thread-unsuspend (local.get $thread-index))
99 (func $just-yield (param $explicit-thread-idx i32)
101 ;; or to the implicit thread, who will acknowledge the cancellation.
102 (if (i32.ne (call $thread-yield) (i32.const 0)) (then unreachable))
105 ;; Initialize the function table that will be used by thread.new-indirect
110 (local $thread-index i32)
111 … ;; Spawn a new thread that will wake us up from our uncancellable suspend; we'll switch to it next
112 (local.set $thread-index
113 … (call $thread-new-indirect (global.get $just-yield-ftbl-idx) (call $thread-index)))
116 …;; wait on the future to be written, then yield to the spawned thread. This means that cancellatio…
122 …;; Yield to the spawned thread uncancellably. We should eventually be rescheduled without being no…
124 …(if (i32.ne (call $thread-yield-to-suspended (local.get $thread-index)) (i32.const 0)) (then unrea…
125 … ;; Yield to the spawned thread again. This time we should see the cancellation immediately.
126 …(if (i32.ne (call $thread-yield-to-suspended-cancellable (local.get $thread-index)) (i32.const 1))…
131 ;; Set up the arguments for the wake-for-suspend thread start function.
132 ;; It expects a pointer to a structure containing the thread index to resume
136 (i32.store offset=0 (local.get $wake-from-suspend-argp) (call $thread-index))
139 … ;; Spawn a new thread that will wake us up from our uncancellable suspend and schedule
141 (call $thread-unsuspend
142 …(call $thread-new-indirect (global.get $wake-from-suspend-ftbl-idx) (local.get $wake-from-suspend-…
145 … ;; suspend. We will be woken up by the other thread we spawned above, which will be resumed after
147 (if (i32.ne (call $thread-suspend) (i32.const 0)) (then unreachable))
149 (if (i32.ne (call $thread-suspend-cancellable) (i32.const 1)) (then unreachable))
154 (local $thread-index i32)
155 ;; Set up the arguments for the wake-for-suspend thread start function.
156 ;; It expects a pointer to a structure containing the thread index to resume
160 (i32.store offset=0 (local.get $wake-from-suspend-argp) (call $thread-index))
163 … ;; Spawn a new thread that will wake us up from our uncancellable suspend; we'll switch to it next
164 (local.set $thread-index
165 …(call $thread-new-indirect (global.get $wake-from-suspend-ftbl-idx) (local.get $wake-from-suspend-…
167 ;; Request suspension by switching to the spawned thread.
169 … ;; We will be woken up by the other thread we spawned above, which will be resumed after
171 …(if (i32.ne (call $thread-suspend-to-suspended (local.get $thread-index)) (i32.const 0)) (then unr…
173 …(if (i32.ne (call $thread-suspend-to-suspended-cancellable (local.get $thread-index)) (i32.const 1…
180 ;; Get access to `thread.new-indirect` that uses the table from libc
185 (core func $thread-new-indirect
186 (canon thread.new-indirect $start-func-ty (table $indirect-function-table)))
187 (core func $thread-yield (canon thread.yield))
188 (core func $thread-yield-cancellable (canon thread.yield cancellable))
189 (core func $thread-index (canon thread.index))
190 (core func $thread-yield-to-suspended (canon thread.yield-to-suspended))
191 … (core func $thread-yield-to-suspended-cancellable (canon thread.yield-to-suspended cancellable))
192 (core func $thread-unsuspend (canon thread.unsuspend))
193 (core func $thread-suspend-to-suspended (canon thread.suspend-to-suspended))
194 …(core func $thread-suspend-to-suspended-cancellable (canon thread.suspend-to-suspended cancellable…
195 (core func $thread-suspend (canon thread.suspend))
196 (core func $thread-suspend-cancellable (canon thread.suspend cancellable))
208 (export "thread.new-indirect" (func $thread-new-indirect))
209 (export "thread.index" (func $thread-index))
210 (export "thread.yield-to-suspended" (func $thread-yield-to-suspended))
211 … (export "thread.yield-to-suspended-cancellable" (func $thread-yield-to-suspended-cancellable))
212 (export "thread.yield" (func $thread-yield))
213 (export "thread.yield-cancellable" (func $thread-yield-cancellable))
214 (export "thread.suspend-to-suspended" (func $thread-suspend-to-suspended))
215 … (export "thread.suspend-to-suspended-cancellable" (func $thread-suspend-to-suspended-cancellable))
216 (export "thread.suspend" (func $thread-suspend))
217 (export "thread.suspend-cancellable" (func $thread-suspend-cancellable))
218 (export "thread.unsuspend" (func $thread-unsuspend))
252 (import "" "thread.yield" (func $thread-yield (result i32)))
271 … ;; Calling run-suspend/suspend-to-suspended will start the thread, which will suspend.
287 ;; Ensure that the thread started
353 (core func $thread.yield (canon thread.yield))
370 (export "thread.yield" (func $thread.yield))