yewstack / prokio

An asynchronous runtime compatible with WebAssembly and non-WebAssembly targets.
Apache License 2.0
68 stars 7 forks source link

Prokio RwLock can not be sent across threads #7

Closed maxall41 closed 1 year ago

maxall41 commented 1 year ago

I'm trying to migrate an existing project from tokio to prokio for WASM support. But I't seems that unlike tokio RwLocks prokio RwLocks can not be sent across threads. Am I just doing something wrong here? Or Is there a reason for this?

Whenever I try to use one I get an error like:

future cannot be sent between threads safely future created by async block is not `Send` Help: within `prokio::pinned::RwLock<std::option::Option<std::string::String>>`, the trait `std::marker::Sync` is not implemented for `std::cell::UnsafeCell<std::vec::Vec<std::task::Waker>>` Note: captured value is not `Send` because `&mut` references cannot be sent unless their referent is `Send` Note: required for the cast from `[async block@src/actions/channel_manager.rs:44:37: 46:6]` to the object type `dyn futures::Future<Output = std::result::Result<(), actions::channel_manager::CreateJobError>> + std::marker::Send`

This even happens when not run inside a prokio task for some reason...

futursolo commented 1 year ago

This is by design. Prokio futures are being pinned to 1 thread. All subsequent futures will also be spawned to the same thread. It is faster and smaller to use a pinned sunchronisation. However, it cannot be sent across threads.

If you are considering to use RwLock across threads, you can continue to use tokio::sync.