Skip to content

feat(jco): Cooperative threading - #2282

Open
TartanLlama wants to merge 3 commits into
bytecodealliance:mainfrom
TartanLlama:sy/coop-threading
Open

TartanLlama wants to merge 3 commits into
bytecodealliance:mainfrom
TartanLlama:sy/coop-threading

Conversation

@TartanLlama

@TartanLlama TartanLlama commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Implements cooperative threading primitives and adds tests for validation.

I plan on porting more of the posix test suite over in time.

@TartanLlama
TartanLlama marked this pull request as draft October 20, 2026 16:45
@TartanLlama

Copy link
Copy Markdown
Contributor Author

@vados-cosmonic the test-extended failures here are I think due to that suite using a published version of jco-transpile rather than the updated version. How do you usually deal with that?

@vados-cosmonic

Copy link
Copy Markdown
Collaborator

Hey @TartanLlama so there are basically two easy options:

  1. test.skip the test and add a TODO(unskip) comment
  2. use a workspace: dependency for jco-transpile temporarily in jco (which is where the extended tests run)

Generally just to make sure things work you can do (2) then (1) -- then I'll re-enable these tests once the newer version of jco-transpile is out.

@TartanLlama
TartanLlama marked this pull request as ready for review October 21, 2026 14:02
vados-cosmonic
vados-cosmonic previously approved these changes Oct 26, 2026

@vados-cosmonic vados-cosmonic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

This is fantastic work thanks @TartanLlama !

Most of my comments are nits (or super nits), so I'm going to get this in and we can get on our way to unskipping the tests.

Normally, consumers will not be impacted by this unless they actually opt in to using threads via how the intrinsics are puleld in so there should not be disruption there/it should be invisible other than jco-transpile being a slightly heavier build-time dep.

// ordinary ready wait, it cannot take the immediate-completion
// shortcut.
const keepGoing = await task.immediateSuspend({{
return thread.suspend({{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Very glad to finally be rid of the pretend-single-thread machinery.

Comment thread crates/js-component-bindgen/src/intrinsics/p3/async_task.rs
Comment thread crates/js-component-bindgen/src/intrinsics/p3/async_task.rs
Comment thread crates/js-component-bindgen/src/intrinsics/p3/host.rs Outdated
assert!(source.contains("callingWasmExport: true,"));
assert!(source.contains("task.enterSync();"));
assert!(source.contains("return _withGlobalCurrentTaskMeta({"));
assert!(source.contains("return _withGlobalCurrentThreadMeta({"));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup thanks for updating these -- normally checking the source is silly but in this case since we're kind of doing a transpile thing/outputting the code, I figured it was not completely unreasonable.

We can delete a ton of this once the runtime is externalized.

(None, None)
};

// Wrap the realloc function to disable leaving the component state while it is executing

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this!

@vados-cosmonic

Copy link
Copy Markdown
Collaborator

Basically everything I have here as comments is just fine in a follow-up, but left them for posterity

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants