Skip to content
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

Add example with multiple threads creation #1826

Conversation

eloparco
Copy link
Contributor

The example shows the creation of multiple threads. Thread spawn failure and thread identifier allocation are tested.
Now written as an example, it uses asserts so that it can be easily converted into a test once a test suite is created #1790.

@yamt
Copy link
Collaborator

yamt commented Dec 23, 2022

FYI, there are a few test efforts:
wasi level tests: WebAssembly/wasi-threads#19
libc level tests: WebAssembly/wasi-libc#369


printf("Created thread with id = %d\n", thread_id);
assert(thread_id == thread_ids[0]
&& "New thread must reuse previously-released identifier");
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • it seems racy as the first thread might be still running
  • i'm not sure if it's a good idea to test this kind of implementation details (how ids are reused) in these samples.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about the race condition, but I definitely agree that the check on the id is an implementation detail and should not be tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's unsafe is maybe that, after __builtin_wasm_memory_atomic_wait32() in the main thread, I can't assume that the thread created has finished and it's possible to create a new thread.

@loganek
Copy link
Collaborator

loganek commented Jan 3, 2023

I wonder if we actually need this example as it doesn't present any new feature that's already not in no_pthread.c already?

@eloparco
Copy link
Contributor Author

eloparco commented Jan 3, 2023

It's to test the failure and re-attempt on thread creation once the thread number limit is reached. Probably it doesn't add anything, I'll close the PR

@eloparco eloparco closed this Jan 3, 2023
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.

3 participants