@@ -61,11 +61,11 @@ specified here.
6161 * [ ` canon {stream,future}.drop-{readable,writable} ` ] ( #-canon-streamfuturedrop-readablewritable ) 🔀
6262 * [ ` canon thread.index ` ] ( #-canon-threadindex ) 🧵
6363 * [ ` canon thread.new-indirect ` ] ( #-canon-threadnew-indirect ) 🧵
64- * [ ` canon thread.switch-to ` ] ( #-canon-threadswitch-to ) 🧵
65- * [ ` canon thread.suspend ` ] ( #-canon-threadsuspend ) 🧵
6664 * [ ` canon thread.resume-later ` ] ( #-canon-threadresume-later ) 🧵
67- * [ ` canon thread.yield-to ` ] ( #-canon-threadyield-to ) 🧵
65+ * [ ` canon thread.suspend ` ] ( #-canon-threadsuspend ) 🧵
6866 * [ ` canon thread.yield ` ] ( #-canon-threadyield ) 🧵
67+ * [ ` canon thread.switch-to ` ] ( #-canon-threadswitch-to ) 🧵
68+ * [ ` canon thread.yield-to ` ] ( #-canon-threadyield-to ) 🧵
6969 * [ ` canon error-context.new ` ] ( #-canon-error-contextnew ) 📝
7070 * [ ` canon error-context.debug-message ` ] ( #-canon-error-contextdebug-message ) 📝
7171 * [ ` canon error-context.drop ` ] ( #-canon-error-contextdrop ) 📝
@@ -4779,34 +4779,30 @@ actually start executing, Core WebAssembly code must call one of the other
47794779` thread.* ` built-ins defined below.
47804780
47814781
4782- ### 🧵 ` canon thread.switch-to `
4782+ ### 🧵 ` canon thread.resume-later `
47834783
47844784For a canonical definition:
47854785``` wat
4786- (canon thread.switch-to $cancellable? (core func $switch-to ))
4786+ (canon thread.resume-later (core func $resume-later ))
47874787```
47884788validation specifies:
4789- * ` $switch-to ` is given type ` (func (param $i i32) (result i32)) `
4789+ * ` $resume-later ` is given type ` (func (param $i i32)) `
47904790
4791- Calling ` $switch-to ` invokes the following function which loads a thread at
4791+ Calling ` $resume-later ` invokes the following function which loads a thread at
47924792index ` $i ` from the current component instance's ` threads ` table, traps if it's
4793- not [ suspended] , and then switches to that thread, leaving the [ current thread ]
4794- suspended .
4793+ not [ suspended] , and then marks that thread as ready to run at some
4794+ nondeterministic point in the future chosen by the embedder .
47954795``` python
4796- def canon_thread_switch_to ( cancellable , i ):
4796+ def canon_thread_resume_later ( i ):
47974797 thread = current_thread()
47984798 trap_if(not thread.task.inst.may_leave)
47994799 other_thread = thread.task.inst.threads.get(i)
48004800 trap_if(not other_thread.suspended())
4801- cancelled = thread.switch_to(cancellable, other_thread )
4802- return [cancelled ]
4801+ other_thread.resume_later( )
4802+ return []
48034803```
4804- If ` cancellable ` is set, then ` thread.switch-to ` will return a ` Cancelled `
4805- value to indicate whether the supertask has already or concurrently requested
4806- cancellation. ` thread.switch-to ` (and other cancellable operations) will only
4807- indicate cancellation once and thus, if a caller is not prepared to propagate
4808- cancellation, they can omit ` cancellable ` so that cancellation is instead
4809- delivered at a later ` cancellable ` call.
4804+ ` thread.resume-later ` never suspends the [ current thread] and so there is no
4805+ possibility of cancellation and thus no ` cancellable ` immediate.
48104806
48114807
48124808### 🧵 ` canon thread.suspend `
@@ -4840,94 +4836,98 @@ cancellation, they can omit `cancellable` so that cancellation is instead
48404836delivered at a later ` cancellable ` call.
48414837
48424838
4843- ### 🧵 ` canon thread.resume-later `
4839+ ### 🧵 ` canon thread.yield `
48444840
48454841For a canonical definition:
48464842``` wat
4847- (canon thread.resume-later (core func $resume-later ))
4843+ (canon thread.yield $cancellable? (core func $yield ))
48484844```
48494845validation specifies:
4850- * ` $resume-later ` is given type ` (func (param $i i32)) `
4846+ * ` $yield ` is given type ` (func (result i32)) `
48514847
4852- Calling ` $resume-later ` invokes the following function which loads a thread at
4853- index ` $i ` from the current component instance's ` threads ` table, traps if it's
4854- not [ suspended] , and then marks that thread as ready to run at some
4855- nondeterministic point in the future chosen by the embedder.
4848+ Calling ` $yield ` invokes the following function which yields execution so that
4849+ others threads can execute, leaving the current thread ready to run at some
4850+ nondeterministic point in the future chosen by the embedder. This allows a
4851+ long-running computation that is not otherwise performing I/O to avoid starving
4852+ other threads in a cooperative setting.
48564853``` python
4857- def canon_thread_resume_later ( i ):
4854+ def canon_thread_yield ( cancellable ):
48584855 thread = current_thread()
48594856 trap_if(not thread.task.inst.may_leave)
4860- other_thread = thread.task.inst.threads.get(i)
4861- trap_if(not other_thread.suspended())
4862- other_thread.resume_later()
4863- return []
4857+ cancelled = thread.yield_(cancellable)
4858+ return [cancelled]
48644859```
4865- ` thread.resume-later ` never suspends the [ current thread] and so there is no
4866- possibility of cancellation and thus no ` cancellable ` immediate.
4860+ If a non-` async ` -typed function export that has not yet returned a value
4861+ transitively calls ` thread.yield ` , it returns immediately without blocking
4862+ (instead of trapping, as with other possibly-blocking operations like
4863+ ` waitable-set.wait ` ). This is because, unlike other built-ins, ` thread.yield `
4864+ may be scattered liberally throughout code that might show up in the transitive
4865+ call tree of a synchronous function call.
48674866
4867+ If ` cancellable ` is set, then ` thread.yield ` will return a ` Cancelled `
4868+ value indicating whether the supertask has already or concurrently requested
4869+ cancellation. ` thread.yield ` (and other cancellable operations) will only
4870+ indicate cancellation once and thus, if a caller is not prepared to propagate
4871+ cancellation, they can omit ` cancellable ` so that cancellation is instead
4872+ delivered at a later ` cancellable ` call.
48684873
4869- ### 🧵 ` canon thread.yield-to `
4874+
4875+ ### 🧵 ` canon thread.switch-to `
48704876
48714877For a canonical definition:
48724878``` wat
4873- (canon thread.yield -to $cancellable? (core func $yield -to))
4879+ (canon thread.switch -to $cancellable? (core func $switch -to))
48744880```
48754881validation specifies:
4876- * ` $yield -to ` is given type ` (func (param $i i32) (result i32)) `
4882+ * ` $switch -to ` is given type ` (func (param $i i32) (result i32)) `
48774883
4878- Calling ` $yield -to ` invokes the following function which loads a thread at
4884+ Calling ` $switch -to ` invokes the following function which loads a thread at
48794885index ` $i ` from the current component instance's ` threads ` table, traps if it's
48804886not [ suspended] , and then switches to that thread, leaving the [ current thread]
4881- ready to run at some nondeterministic point in the future chosen by the
4882- embedder.
4887+ suspended.
48834888``` python
4884- def canon_thread_yield_to (cancellable , i ):
4889+ def canon_thread_switch_to (cancellable , i ):
48854890 thread = current_thread()
48864891 trap_if(not thread.task.inst.may_leave)
48874892 other_thread = thread.task.inst.threads.get(i)
48884893 trap_if(not other_thread.suspended())
4889- cancelled = thread.yield_to (cancellable, other_thread)
4894+ cancelled = thread.switch_to (cancellable, other_thread)
48904895 return [cancelled]
48914896```
4892- If ` cancellable ` is set, then ` thread.yield -to ` will return a ` Cancelled `
4893- value indicating whether the supertask has already or concurrently requested
4894- cancellation. ` thread.yield -to ` (and other cancellable operations) will only
4897+ If ` cancellable ` is set, then ` thread.switch -to ` will return a ` Cancelled `
4898+ value to indicate whether the supertask has already or concurrently requested
4899+ cancellation. ` thread.switch -to ` (and other cancellable operations) will only
48954900indicate cancellation once and thus, if a caller is not prepared to propagate
48964901cancellation, they can omit ` cancellable ` so that cancellation is instead
48974902delivered at a later ` cancellable ` call.
48984903
48994904
4900- ### 🧵 ` canon thread.yield `
4905+ ### 🧵 ` canon thread.yield-to `
49014906
49024907For a canonical definition:
49034908``` wat
4904- (canon thread.yield $cancellable? (core func $yield))
4909+ (canon thread.yield-to $cancellable? (core func $yield-to ))
49054910```
49064911validation specifies:
4907- * ` $yield ` is given type ` (func (result i32)) `
4912+ * ` $yield-to ` is given type ` (func (param $i i32) (result i32)) `
49084913
4909- Calling ` $yield ` invokes the following function which yields execution so that
4910- others threads can execute, leaving the current thread ready to run at some
4911- nondeterministic point in the future chosen by the embedder. This allows a
4912- long-running computation that is not otherwise performing I/O to avoid starving
4913- other threads in a cooperative setting .
4914+ Calling ` $yield-to ` invokes the following function which loads a thread at
4915+ index ` $i ` from the current component instance's ` threads ` table, traps if it's
4916+ not [ suspended ] , and then switches to that thread, leaving the [ current thread ]
4917+ ready to run at some nondeterministic point in the future chosen by the
4918+ embedder .
49144919``` python
4915- def canon_thread_yield (cancellable ):
4920+ def canon_thread_yield_to (cancellable , i ):
49164921 thread = current_thread()
49174922 trap_if(not thread.task.inst.may_leave)
4918- cancelled = thread.yield_(cancellable)
4923+ other_thread = thread.task.inst.threads.get(i)
4924+ trap_if(not other_thread.suspended())
4925+ cancelled = thread.yield_to(cancellable, other_thread)
49194926 return [cancelled]
49204927```
4921- If a non-` async ` -typed function export that has not yet returned a value
4922- transitively calls ` thread.yield ` , it returns immediately without blocking
4923- (instead of trapping, as with other possibly-blocking operations like
4924- ` waitable-set.wait ` ). This is because, unlike other built-ins, ` thread.yield `
4925- may be scattered liberally throughout code that might show up in the transitive
4926- call tree of a synchronous function call.
4927-
4928- If ` cancellable ` is set, then ` thread.yield ` will return a ` Cancelled `
4928+ If ` cancellable ` is set, then ` thread.yield-to ` will return a ` Cancelled `
49294929value indicating whether the supertask has already or concurrently requested
4930- cancellation. ` thread.yield ` (and other cancellable operations) will only
4930+ cancellation. ` thread.yield-to ` (and other cancellable operations) will only
49314931indicate cancellation once and thus, if a caller is not prepared to propagate
49324932cancellation, they can omit ` cancellable ` so that cancellation is instead
49334933delivered at a later ` cancellable ` call.
0 commit comments