@@ -60,11 +60,11 @@ specified here.
6060 * [ ` canon {stream,future}.drop-{readable,writable} ` ] ( #-canon-streamfuturedrop-readablewritable ) 🔀
6161 * [ ` canon thread.index ` ] ( #-canon-threadindex ) 🧵
6262 * [ ` canon thread.new-indirect ` ] ( #-canon-threadnew-indirect ) 🧵
63- * [ ` canon thread.switch-to ` ] ( #-canon-threadswitch-to ) 🧵
64- * [ ` canon thread.suspend ` ] ( #-canon-threadsuspend ) 🧵
6563 * [ ` canon thread.resume-later ` ] ( #-canon-threadresume-later ) 🧵
66- * [ ` canon thread.yield-to ` ] ( #-canon-threadyield-to ) 🧵
64+ * [ ` canon thread.suspend ` ] ( #-canon-threadsuspend ) 🧵
6765 * [ ` canon thread.yield ` ] ( #-canon-threadyield ) 🧵
66+ * [ ` canon thread.switch-to ` ] ( #-canon-threadswitch-to ) 🧵
67+ * [ ` canon thread.yield-to ` ] ( #-canon-threadyield-to ) 🧵
6868 * [ ` canon error-context.new ` ] ( #-canon-error-contextnew ) 📝
6969 * [ ` canon error-context.debug-message ` ] ( #-canon-error-contextdebug-message ) 📝
7070 * [ ` canon error-context.drop ` ] ( #-canon-error-contextdrop ) 📝
@@ -4632,33 +4632,29 @@ actually start executing, Core WebAssembly code must call one of the other
46324632` thread.* ` built-ins defined below.
46334633
46344634
4635- ### 🧵 ` canon thread.switch-to `
4635+ ### 🧵 ` canon thread.resume-later `
46364636
46374637For a canonical definition:
46384638``` wat
4639- (canon thread.switch-to $cancellable? (core func $switch-to ))
4639+ (canon thread.resume-later (core func $resume-later ))
46404640```
46414641validation specifies:
4642- * ` $switch-to ` is given type ` (func (param $i i32) (result i32)) `
4642+ * ` $resume-later ` is given type ` (func (param $i i32)) `
46434643
4644- Calling ` $switch-to ` invokes the following function which loads a thread at
4644+ Calling ` $resume-later ` invokes the following function which loads a thread at
46454645index ` $i ` from the current component instance's ` threads ` table, traps if it's
4646- not [ suspended] , and then switches to that thread, leaving the [ current thread ]
4647- suspended .
4646+ not [ suspended] , and then marks that thread as ready to run at some
4647+ nondeterministic point in the future chosen by the embedder .
46484648``` python
4649- def canon_thread_switch_to ( cancellable , thread , i ):
4649+ def canon_thread_resume_later ( thread , i ):
46504650 trap_if(not thread.task.inst.may_leave)
46514651 other_thread = thread.task.inst.threads.get(i)
46524652 trap_if(not other_thread.suspended())
4653- resume_arg = thread.switch_to(cancellable, other_thread )
4654- return [resume_arg ]
4653+ other_thread.resume_later( )
4654+ return []
46554655```
4656- If ` cancellable ` is set, then ` thread.switch-to ` will return a ` ResumeArg ` value
4657- to indicate whether the supertask has already or concurrently requested
4658- cancellation. ` thread.switch-to ` (and other cancellable operations) will only
4659- indicate cancellation once and thus, if a caller is not prepared to propagate
4660- cancellation, they can omit ` cancellable ` so that cancellation is instead
4661- delivered at a later ` cancellable ` call.
4656+ ` thread.resume-later ` never suspends the [ current thread] and so there is no
4657+ possibility of cancellation and thus no ` cancellable ` immediate.
46624658
46634659
46644660### 🧵 ` canon thread.suspend `
@@ -4691,91 +4687,95 @@ cancellation, they can omit `cancellable` so that cancellation is instead
46914687delivered at a later ` cancellable ` call.
46924688
46934689
4694- ### 🧵 ` canon thread.resume-later `
4690+ ### 🧵 ` canon thread.yield `
46954691
46964692For a canonical definition:
46974693``` wat
4698- (canon thread.resume-later (core func $resume-later ))
4694+ (canon thread.yield $cancellable? (core func $yield ))
46994695```
47004696validation specifies:
4701- * ` $resume-later ` is given type ` (func (param $i i32)) `
4697+ * ` $yield ` is given type ` (func (result i32)) `
47024698
4703- Calling ` $resume-later ` invokes the following function which loads a thread at
4704- index ` $i ` from the current component instance's ` threads ` table, traps if it's
4705- not [ suspended] , and then marks that thread as ready to run at some
4706- nondeterministic point in the future chosen by the embedder.
4699+ Calling ` $yield ` invokes the following function which yields execution so that
4700+ others threads can execute, leaving the current thread ready to run at some
4701+ nondeterministic point in the future chosen by the embedder. This allows a
4702+ long-running computation that is not otherwise performing I/O to avoid starving
4703+ other threads in a cooperative setting.
47074704``` python
4708- def canon_thread_resume_later ( thread , i ):
4705+ def canon_thread_yield ( cancellable , thread ):
47094706 trap_if(not thread.task.inst.may_leave)
4710- other_thread = thread.task.inst.threads.get(i)
4711- trap_if(not other_thread.suspended())
4712- other_thread.resume_later()
4713- return []
4707+ resume_arg = thread.yield_(cancellable)
4708+ return [resume_arg]
47144709```
4715- ` thread.resume-later ` never suspends the [ current thread] and so there is no
4716- possibility of cancellation and thus no ` cancellable ` immediate.
4710+ If called during a non-` async ` -typed function export, this function does not
4711+ trap. Instead, ` Thread.yield_ ` will simply return without blocking. This allows
4712+ ` thread.yield ` calls to be sprinkled liberally throughout code. Furthermore,
4713+ even when called from an ` async ` -typed function export, ` Thread.yield_ `
4714+ nondeterministically allows the embedder to continue executing the current thread
4715+ based on heuristics (like timing).
47174716
4717+ If ` cancellable ` is set, then ` thread.yield ` will return a ` ResumeArg ` value
4718+ indicating whether the supertask has already or concurrently requested
4719+ cancellation. ` thread.yield ` (and other cancellable operations) will only
4720+ indicate cancellation once and thus, if a caller is not prepared to propagate
4721+ cancellation, they can omit ` cancellable ` so that cancellation is instead
4722+ delivered at a later ` cancellable ` call.
47184723
4719- ### 🧵 ` canon thread.yield-to `
4724+
4725+ ### 🧵 ` canon thread.switch-to `
47204726
47214727For a canonical definition:
47224728``` wat
4723- (canon thread.yield -to $cancellable? (core func $yield -to))
4729+ (canon thread.switch -to $cancellable? (core func $switch -to))
47244730```
47254731validation specifies:
4726- * ` $yield -to ` is given type ` (func (param $i i32) (result i32)) `
4732+ * ` $switch -to ` is given type ` (func (param $i i32) (result i32)) `
47274733
4728- Calling ` $yield -to ` invokes the following function which loads a thread at
4734+ Calling ` $switch -to ` invokes the following function which loads a thread at
47294735index ` $i ` from the current component instance's ` threads ` table, traps if it's
47304736not [ suspended] , and then switches to that thread, leaving the [ current thread]
4731- ready to run at some nondeterministic point in the future chosen by the
4732- embedder.
4737+ suspended.
47334738``` python
4734- def canon_thread_yield_to (cancellable , thread , i ):
4739+ def canon_thread_switch_to (cancellable , thread , i ):
47354740 trap_if(not thread.task.inst.may_leave)
47364741 other_thread = thread.task.inst.threads.get(i)
47374742 trap_if(not other_thread.suspended())
4738- resume_arg = thread.yield_to (cancellable, other_thread)
4743+ resume_arg = thread.switch_to (cancellable, other_thread)
47394744 return [resume_arg]
47404745```
4741- If ` cancellable ` is set, then ` thread.yield -to ` will return a ` ResumeArg ` value
4742- indicating whether the supertask has already or concurrently requested
4743- cancellation. ` thread.yield -to ` (and other cancellable operations) will only
4746+ If ` cancellable ` is set, then ` thread.switch -to ` will return a ` ResumeArg ` value
4747+ to indicate whether the supertask has already or concurrently requested
4748+ cancellation. ` thread.switch -to ` (and other cancellable operations) will only
47444749indicate cancellation once and thus, if a caller is not prepared to propagate
47454750cancellation, they can omit ` cancellable ` so that cancellation is instead
47464751delivered at a later ` cancellable ` call.
47474752
47484753
4749- ### 🧵 ` canon thread.yield `
4754+ ### 🧵 ` canon thread.yield-to `
47504755
47514756For a canonical definition:
47524757``` wat
4753- (canon thread.yield $cancellable? (core func $yield))
4758+ (canon thread.yield-to $cancellable? (core func $yield-to ))
47544759```
47554760validation specifies:
4756- * ` $yield ` is given type ` (func (result i32)) `
4761+ * ` $yield-to ` is given type ` (func (param $i i32) (result i32)) `
47574762
4758- Calling ` $yield ` invokes the following function which yields execution so that
4759- others threads can execute, leaving the current thread ready to run at some
4760- nondeterministic point in the future chosen by the embedder. This allows a
4761- long-running computation that is not otherwise performing I/O to avoid starving
4762- other threads in a cooperative setting .
4763+ Calling ` $yield-to ` invokes the following function which loads a thread at
4764+ index ` $i ` from the current component instance's ` threads ` table, traps if it's
4765+ not [ suspended ] , and then switches to that thread, leaving the [ current thread ]
4766+ ready to run at some nondeterministic point in the future chosen by the
4767+ embedder .
47634768``` python
4764- def canon_thread_yield (cancellable , thread ):
4769+ def canon_thread_yield_to (cancellable , thread , i ):
47654770 trap_if(not thread.task.inst.may_leave)
4766- resume_arg = thread.yield_(cancellable)
4771+ other_thread = thread.task.inst.threads.get(i)
4772+ trap_if(not other_thread.suspended())
4773+ resume_arg = thread.yield_to(cancellable, other_thread)
47674774 return [resume_arg]
47684775```
4769- If called during a non-` async ` -typed function export, this function does not
4770- trap. Instead, ` Thread.yield_ ` will simply return without blocking. This allows
4771- ` thread.yield ` calls to be sprinkled liberally throughout code. Furthermore,
4772- even when called from an ` async ` -typed function export, ` Thread.yield_ `
4773- nondeterministically allows the embedder to continue executing the current thread
4774- based on heuristics (like timing).
4775-
4776- If ` cancellable ` is set, then ` thread.yield ` will return a ` ResumeArg ` value
4776+ If ` cancellable ` is set, then ` thread.yield-to ` will return a ` ResumeArg ` value
47774777indicating whether the supertask has already or concurrently requested
4778- cancellation. ` thread.yield ` (and other cancellable operations) will only
4778+ cancellation. ` thread.yield-to ` (and other cancellable operations) will only
47794779indicate cancellation once and thus, if a caller is not prepared to propagate
47804780cancellation, they can omit ` cancellable ` so that cancellation is instead
47814781delivered at a later ` cancellable ` call.
0 commit comments