-
Notifications
You must be signed in to change notification settings - Fork 41
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
implement thread-spawn #81
Conversation
80f8d74
to
9959142
Compare
I try running wasm-ld using |
bjorn3/rust#8 links lld directly into the rustc.wasm binary such that it doesn't need to run an external linker executable. |
Have you reached the level of availability yet? |
What do you mean? |
Does it work? |
It works in wasmtime at least: $ echo 'fn main() { println!("Hello World!"); }' | wasmtime run -Sthreads=y -Spreview2=n --dir tmp::/ --dir dist --env RUST_MIN_STACK=16777216 dist/bin/rustc.wasm - --sysroot dist --target wasm32-wasip1
Linking using LC_ALL="C" VSLANG="1033" "rust-lld" "-flavor" "wasm" [...]
$ wasmtime run tmp/rust_out.wasm
Hello World! |
ok, I'll try it after it's compiled on my server |
Change to use the first stdio fd_write can be async enabled move but wasm throw error: memory access out of bounds
Report on the result of using wasm-ld I should test wasm-ld with wasmtime, but first, I plan to try bjorn3/rust#8. |
On Unix glob patterns are normally handled by the shell, not by the program itself. |
Using bjorn3/rust#8, I successfully compiled and executed it directly on the web! example: wasi_multi_threads_rustc |
Great work! Just as a heads up: It will almost certainly take me at least a week before I have time to review this. |
I've written quite a lot of comments, but since there are many files and the structure is quite complex, feel free to ask if you have any concerns! |
I don't understand poll_oneoff at all, but since I'm implementing a file system that can be accessed by multiple workers, it's possible that I can implement poll_oneoff as well. |
It's similar to epoll on Linux, kqueue on BSD. Basically it allows you to ask a bunch of fd's at once if they have any data ready to ready from or can be written too and I believe also allows setting a timeout. This is what async rust internally uses on wasi. It is mostly useful for streams of data like network sockets or reading from stdin. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot more code than I expected. I've left a couple of small comments, but I'm no way near done reviewing this. It will likely take at least a couple of weeks before I've fully reviewed this. Would it be possible to have the thread support in a separate package? If so if it works locally for me, I think it could be merged mostly as is with a disclaimer that it is less production ready than the rest of browser_wasi_shim.
src/wasi_farm/shared_array_buffer/worker_background/worker_blob.ts
Outdated
Show resolved
Hide resolved
We are dependent on classes such as Fd, File, and Directory. Since I have only modified src/wasi.ts and have isolated everything in the src/wasi_farm directory, I believe it is quite feasible to create a separate npm package that has @bjorn3/browser_wasi_shim as a dependency. |
Regarding the wasm-ification of cargo: I won’t be submitting a pull request because the current state of cargo is too problematic. However, in the process, I did discover a bug related to this pull request. Additionally, I implemented a special function to run wasm within virtual files, and I’d like to add that as well. Would that be acceptable? |
If you add it outside of the |
Indeed. I'll submit the bug fix only. |
What shall we do? |
…itten fd_renumber. add .vscode on .gitignore. rm unused change. Pass fd_map as is to child threads. Change .gitmodules to tabs. reset run-testsuite.sh Minor modifications to the code. patch about null equal undefined on parse JSON.
Please split the thread support into a new package that depends on the main browser_wasi_shim package. |
Would you prefer to go with a monorepo, or should I set up a separate repository? |
Having it in this repo is fine. |
Ok, I try monorepo. |
By the way, do you have a good package name? |
Maybe browser_wasi_shim-threads? |
52cf4ec
to
51822df
Compare
I splited, so check please. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple minor changes and I will merge it.
@@ -0,0 +1,21 @@ | |||
# A pure javascript shim for WASI Preview 1 threads | |||
|
|||
This project is implement threads on browser_wasi_shim |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This project is implement threads on browser_wasi_shim | |
This project implement threads on browser_wasi_shim |
nit
(did you forget to push?) |
Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
Oh, I see. I couldn’t pull because I resolved it without committing. My apologies and thank you so much! |
Thanks a lot for working on this! |
Oh, my apologies, I just finished making the corrections, so it was a bit too early to merge. |
My bad. I fixed the typo you hadn't resolved yet when I merged this PR myself, but for any other changes please open another PR. |
ok. |
I have implemented a multi-thread accessible file system, which was a prerequisite for wasi-threads.
I haven’t created any tests as I’m not quite sure how to do that.
Features:
Usable across multiple workers
Create a WASIFarm and obtain a WASIFarmRef using .get_ref().
WASIFarmRef can be sent via postMessage.
Be cautious, as classes will also be sent as objects via postMessage.
Multiple WASIFarm can be used to create WASIFarmAnimal.
For Stdio, the WASIRef at the end takes precedence.
Files passed to WASIRef will be treated as if they exist.
WASIFarmAnimal can be accessed using .wasiImport.
Each WASIFarmAnimal can only have one .wasiImport.
When creating a WASIFarmAnimal, you can pass override_fd_maps to change the files accessible by each WASIFarmRef. This allows passing file descriptors to child processes.
For usage examples, please refer to the wasi_threads example.
I ported the example rustc and it works fine!
Issues:
Uses SharedArrayBuffer
Since the communication portion is separated, by understanding the polyfill found at https://github.com/WebReflection/sabayon, it should be possible to implement this in a non-SharedArrayBuffer environment.
Commands used across multiple files cannot yet be used across multiple Farms
I will address this eventually.
File pointers are not process-dependent
This could be achieved by using pread to implement read, but I’m not sure if it's correct to make file pointers process-dependent in the first place.
Parts that haven’t been tested may be unreliable
If 100% is the amount of code I can manage, then this project has reached 120%, so I may not be able to manage everything.
It should be correct, but atomics.waitAsync gives tsc error.
Motivation is running low