Sending Rc objects to another thread

⚓ Rust    📅 2025-06-20    👤 surdeus    👁️ 6      

surdeus

Warning

This post was published 54 days ago. The information described in this article may have changed.

Rc is !Send. Rc objects cannot be shared between threads due to race conditions on dropping. However, if all clones of an Rc object were to be sent to another thread as one, it seems to me that there would be no issue with safety.

Is there any way of using Rc<RefCell> inside a spawned tokio task without pinning it to a single thread? Arc is out of the question due to it requiring the contained type to by Sync for it to be Send.

If the whole task is sent to another thread, then all clones of an Rc by definition would also be sent to that thread. !Send seems too restrictive.

5 posts - 3 participants

Read full topic

🏷️ rust_feed