-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
single_threaded_task_pool
scope
api doesn't work in wasm
#1924
Comments
I'm not sure if the mutex is the problematic part here - because of the code surrounding code, these mutexes shouldn't be contested. The only other place these mutexes could be locked is the task they correspond to, and the above loop should ensure all tasks have already been completed. The locking here should never block. |
they are locked to write the result here:
and locked to read the result here:
|
|
just tried that, doesn't work 😞
|
Yes, but shouldn't the |
no, it just poll each future once: https://docs.rs/async-executor/1.4.1/async_executor/struct.LocalExecutor.html#method.try_tick |
But it's executed in a while loop, and try_tick only returns false if there are no tasks left to run: https://docs.rs/async-executor/1.4.1/src/async_executor/lib.rs.html#172 |
And, the unwrap that panics in your last code is the second unwrap:
|
it pops the tasks from the queue, poll it once, and go to the next. it's not waiting for tasks to be finished or putting them back in the queue |
Yup that's with the change suggested by @bjorn3 and a mystery to me... unless |
Alright, with that context I think I solved the reason why this bug exists: The code, as evident by the comment relies on that loop finishing all tasks. However, this isn't the case if the tasks contain an |
And the code in the original bug report fundamentally never would've ran on the web, as it requires you block on the main thread until the IO operation necessary to finish loading is complete. This does run on native because native uses |
Exactly my point, we can't use the single threaded task pool on the web where it's the only place it's used 👍 |
The single-threaded task pool (imo) is a temporary solution until threaded wasm matures, and it is used - pretty heavily in fact. The EDIT: The However, the point that awaiting anything that isn't guaranteed to complete in the scope is a very bad idea stands, so the fact that |
Bevy version
0.5 and
d119c1ce14da59089a65373d59715a41d05251ad
Operating system & version
Firefox & Chromium
What you did
Trying to use the task pool to execute several tasks, I hoped to have the same code running in both wasm and native
This works on native!
Building this for wasm32 gives an error:
Indeed,
spawn
requires the future to beSend
in the single_threaded_task_pool. This could probably be removed anyway as it callsspawn_local
which doesn't needSend
bevy/crates/bevy_tasks/src/single_threaded_task_pool.rs
Lines 129 to 131 in d119c1c
Let's try to run this with
spawn_local
to check if it would work better.At least it compiles that way!And crash in the browser
And rightly so. In the
scope
function:bevy/crates/bevy_tasks/src/single_threaded_task_pool.rs
Lines 79 to 83 in d119c1c
The
lock()
is on a mutex, and that can't work because you can't block in wasm...Using the task pool in wasm will work for trivial task that aren't long enough to lock the mutex, but will fail for any real case...
I tried a few things but couldn't get it to work
The text was updated successfully, but these errors were encountered: