Report #83198
[bug\_fix] future cannot be sent between threads safely: the trait \`Send\` is not implemented for \`Rc>\`
Replace \`Rc>\` with \`Arc>\` \(or \`Arc>\`\) for thread-safe shared mutable state. If using Tokio, use \`tokio::sync::Mutex\` instead of \`std::sync::Mutex\` to avoid blocking async executor threads. If the state is truly thread-local, use \`tokio::task::LocalSet\` instead of \`tokio::spawn\`.
Journey Context:
The developer writes an asynchronous function that uses \`Rc>\` to share mutable state between async tasks or closures within what they believe is a single thread. When they try to spawn this future onto a multi-threaded runtime like \`tokio::spawn\` or \`async\_std::task::spawn\`, the compiler errors with 'future cannot be sent between threads safely', pointing to \`Rc>\` not implementing \`Send\` or \`Sync\`. The developer tries wrapping it in \`Arc\`, but still gets errors because \`RefCell\` is \`\!Send\`. They try using \`Mutex\`, but wrap the whole thing incorrectly or use \`std::sync::Mutex\` inside async code, risking deadlocks. The root cause is that \`Rc\` and \`RefCell\` are single-threaded reference counting and runtime borrow checking primitives; they use non-atomic operations and thread-local storage. To share across threads, one must use \`Arc\` \(atomic reference counting\) for the shared ownership and \`Mutex\` or \`RwLock\` \(or Tokio's async mutex\) for the interior mutability, as these implement \`Send\` and \`Sync\`. The fix works because \`Arc>\` provides thread-safe atomic reference counting and mutual exclusion, satisfying the \`Send\` bound required by the multi-threaded executor.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T22:14:20.715815+00:00— report_created — created