diff --git a/design/mvp/Concurrency.md b/design/mvp/Concurrency.md index 9aefc41d..bc037864 100644 --- a/design/mvp/Concurrency.md +++ b/design/mvp/Concurrency.md @@ -128,6 +128,28 @@ Thus, overall, `async` in WIT and the Component Model does not behave like a "color" in the sense described by the popular [What Color Is Your Function?] essay. +The following table summarizes how the behavior of a callee changes, depending +on whether `async` is set as a lifting or lowering ABI option and whether the +component function type is `async`: + +| Component function type | Lift canonical option | Valid? | Effect of callee blocking | Holds instances's exclusive lock? | Can call while instance lock held? | +| ----------------------- | --------------------- | ------ | ------------------------- | --------------------------------- | ---------------------------------- | +| sync | sync | ✅ | Switch to another ready thread in the component instance, trap if there is none | No, but only threads in the same instance and their recursive calls can run until callee returns | Yes | +| sync | async | ❌ | N/A | N/A | N/A | +| async | sync | ✅ | Control returns to caller | While running or blocked | No, call waits until lock is released | +| async | async + callback | ✅ | Control returns to caller | While running or blocked on the stack (not when having returned to the event loop) | No, waits until lock is released | +| async | async stackful | ✅ | Control returns to caller | No | Yes | + +The following table summarizes how the behavior of a caller changes, depending on +how it lowers a callee and the type of the callee: + +| Callee component function type | Lower canonical option | Valid? | Effect on caller when callee blocks | +| ------------------------------ | ---------------------- | ------ | ----------------------------------- | +| sync | sync | ✅ | N/A (Callee traps rather than blocking) | +| sync | async | ❌ | N/A | +| async | sync | ✅ | Caller blocks itself | +| async | async | ✅ | Caller resumes execution - it can await the callee by putting it in a waitable set and also make new calls to the callee instance | + Each time a component export is called, the wasm runtime logically spawns a new [green thread] (as opposed to a [kernel thread]) to execute the export call concurrently with other calls in the runtime. This means that [thread-local