-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: Replace Arc with Rc to fix clippy lint #78
Conversation
Fix the clippy lint: Error: error: usage of an `Arc` that is not `Send` and `Sync`
I'm rather surprised that the compiler is OK with this. |
Took me a minute to figure out what was going on, but the |
Like, yes, that's correct, but the compiler has no way to track that; the mere fact that it isn't |
I think the correct fix there is to unsafely impl Send for InnerStarReference, assuming that is true, and keep the The only reason it wouldn't be true is if it matters which thread the destructor for InnerStarReference runs on:
If that does need to run on the same thread that instantiated it, then unsafe impl Send is a dangerous idea. It kind of begs the question: if there's no need to synchronize access to BindRef, why are we using Arc in the first place? Instead we should instantiate InnerStarReference in some kind of container that never leaves the invoking thread, and hand out &InnerStarReference, thus guaranteeing that the bindings are never destructed on the wrong thread. |
The parallelism in cellranger is using |
Thanks for the explanation, Chris! Closing this PR, superseded by PR |
If there isn't logically ever more than one copy of it, why not just use a |
Boxing doesn't achieve anything here; the reference to it needs to be shared between threads, and |
Well, then it sounds like we do, in fact, need |
The right long-term solution is still to share a scoped immutable reference, but continuing to use |
Arc
withRc
inStarReference
unsafe impl Sync for InnerStarReference
andunsafe impl Send for StarRef
RUST_VERSION
from 1.65.0 to 1.79.0The
StarReference
containing theRc
is cloned in the main thread, the clone is sent to the worker thread, and the worker thread returns the clone back to the main thread, which destructs it and itsRc
, so aRc
is sufficient and anArc
is not needed.https://github.com/10XDev/cellranger/blob/ca2035689090380a46c3f19b9f5a32a375e111c4/lib/rust/cr_lib/src/stages/align_and_count.rs#L814
Fix the clippy lint:
See https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync