Skip to content

Add cross-platform atomics #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 2, 2024
Merged

Add cross-platform atomics #327

merged 3 commits into from
Apr 2, 2024

Conversation

saghul
Copy link
Contributor

@saghul saghul commented Mar 21, 2024

Fixes: #1

@saghul saghul changed the title Add cross-platform atomics WIP - Add cross-platform atomics Mar 21, 2024
@saghul saghul force-pushed the atomics branch 3 times, most recently from 0aec773 to 47f23e6 Compare March 22, 2024 09:44
@saghul saghul changed the title WIP - Add cross-platform atomics Add cross-platform atomics Mar 22, 2024
@saghul saghul marked this pull request as ready for review March 22, 2024 12:54
@saghul
Copy link
Contributor Author

saghul commented Mar 22, 2024

I think this is ready for review!

Looks like there might be a bug somewhere because the test harness has gotten stuck on (some) Linux jobs, it seems.

I guess what remains to be decided is what to do about WASI :-/ It does not support pthreads so we're out of luck (for now). Re-gating the feature with CONFIG_ATOMICS is something I'd like to avoid, in orde to make qjsc generated bytecode portable. Thoughts? Perhaps I could make all APIs return an error on WASI, but then one could make the argument that feature-detection is broken, and they'd have a point...

Edit: I found a way around for WASI. There is some pthreads compatibility in the WASI SDK I had missed!

Copy link
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

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

Not sure why test262 hangs. It looks like it should Just Work.

@saghul saghul force-pushed the atomics branch 3 times, most recently from f523443 to a538568 Compare April 2, 2024 11:57
@saghul
Copy link
Contributor Author

saghul commented Apr 2, 2024

Alright, new strategy. I disabled atomics on Emscripten / WASI, but kept the bytecode compatible by always having the atoms defined.

Threading support is still experimental on wasmtime, so I guess WASI can wait.

Once tests pass this should be good to go.

More Windows portability will follow to enable workers, but that is in the libc, I'm focusing on the engine first.

}
ret = pthread_cond_timedwait(&waiter->cond, &js_atomics_mutex,
&ts);
ret = js_cond_timedwait(&waiter->cond, &js_atomics_mutex, timeout * 1e6 /* to ns */);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bnoordhuis This was the reason for the hang. Timeot is in ms for Atomics.wait but in the C wrapper I take ns like libuv 😅

@saghul
Copy link
Contributor Author

saghul commented Apr 2, 2024

And we are 💚 -- @bnoordhuis PTAL!

@@ -32561,7 +32560,7 @@ typedef enum BCTagEnum {
BC_TAG_OBJECT_REFERENCE,
} BCTagEnum;

#define BC_VERSION 9
#define BC_VERSION 10
Copy link
Contributor

Choose a reason for hiding this comment

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

For my understanding, is the bump necessary because the atom ids change when the #ifdef CONFIG_ATOMICS is removed from quickjs-atom.h?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. That's the source of the bytecode incompatibility.

@saghul saghul merged commit 569b238 into master Apr 2, 2024
@saghul saghul deleted the atomics branch April 2, 2024 19:50
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.

windows + atomics
2 participants