Lines Matching refs:thread

4 …ests for basic functioning of all threading builtins with the implicit thread + one explicit thread
8 ;; Defines the table for the thread start function
11 ;; Defines the thread start function and a function that calls thread.new-indirect
14 (import "" "thread.new-indirect" (func $thread-new-indirect (param i32 i32) (result i32)))
15 (import "" "thread.suspend" (func $thread-suspend (result i32)))
16 … (import "" "thread.yield-to-suspended" (func $thread-yield-to-suspended (param i32) (result i32)))
17 …(import "" "thread.suspend-to-suspended" (func $thread-suspend-to-suspended (param i32) (result i3…
18 (import "" "thread.yield" (func $thread-yield (result i32)))
19 (import "" "thread.index" (func $thread-index (result i32)))
20 (import "" "thread.unsuspend" (func $thread-unsuspend (param i32)))
23 ;; A global that we will set from the spawned thread
25 (global $main-thread-index (mut i32) (i32.const 0))
27 …;; The thread entry point, which sets the global to incrementing values starting from the context …
28 (func $thread-start (param i32)
31 … ;; The main thread switched to us, so is no longer scheduled, so we explicitly schedule it
32 (call $thread-unsuspend (global.get $main-thread-index))
33 ;; Yield back to the main thread (since that is the only other one)
34 (drop (call $thread-yield)
37 ;; The main thread will have explicitly requested suspension, so yield to it directly
38 (drop (call $thread-yield-to-suspended (global.get $main-thread-index)))
41 ;; Reschedule the main thread so that it runs after we exit
42 (call $thread-unsuspend (global.get $main-thread-index))))
43 (export "thread-start" (func $thread-start))
45 ;; Initialize the function table with our thread-start function; this will be
46 ;; used by thread.new-indirect
47 (elem (table $indirect-function-table) (i32.const 0) func $thread-start)
49 ;; The main entry point, which spawns a new thread to run `thread-start`, passing 42
52 ;; Store the main thread's index for the spawned thread to yield to
53 (global.set $main-thread-index (call $thread-index))
54 ;; Create a new thread, which starts suspended, and switch to it
56 (call $thread-suspend-to-suspended
57 (call $thread-new-indirect (i32.const 0) (i32.const 42))))
58 ;; After the thread yields back to us, check that the global was set to 42
60 ;; Suspend ourselves, which will cause the spawned thread to run
61 (drop (call $thread-suspend))
62 … ;; The spawned thread will resume us after incrementing the global, so check that it is now 43
64 ;; Suspend again, which will cause the spawned thread to run again
65 (drop (call $thread-suspend))
66 …;; The spawned thread will reschedule us before it exits, so when we resume here the global should…
73 ;; Get access to `thread.new-indirect` that uses the table from libc
77 (core func $thread-new-indirect
78 (canon thread.new-indirect $start-func-ty (table $indirect-function-table)))
79 (core func $thread-yield (canon thread.yield))
80 (core func $thread-index (canon thread.index))
81 (core func $thread-yield-to-suspended (canon thread.yield-to-suspended))
82 (core func $thread-unsuspend (canon thread.unsuspend))
83 (core func $thread-suspend-to-suspended (canon thread.suspend-to-suspended))
84 (core func $thread-suspend (canon thread.suspend))
90 (export "thread.new-indirect" (func $thread-new-indirect))
91 (export "thread.index" (func $thread-index))
92 (export "thread.yield-to-suspended" (func $thread-yield-to-suspended))
93 (export "thread.yield" (func $thread-yield))
94 (export "thread.suspend-to-suspended" (func $thread-suspend-to-suspended))
95 (export "thread.suspend" (func $thread-suspend))
96 (export "thread.unsuspend" (func $thread-unsuspend))))
104 ;; Test that `thread.index` is exempt from may-leave checks
106 (core func $thread.index (canon thread.index))
109 (import "" "thread.index" (func $thread.index (result i32)))
112 (func (export "post-return") call $thread.index drop)
115 (export "thread.index" (func $thread.index))