Can a non-accessible `Rc` be `Send`?

Let's suppose I have a private module which can't be edited which exports a type wrapping an Rc like so: playground link. The Rc can be cloned multiple times during new (imagine it's a graph structure) but never after.

Does the fact that it's impossible to get a reference to the Rc wrapping the RefCell in any way make the implementation of Send sound? My understanding is that, provided Rc doesn't use any thread locals in its Drop implementation, this should be fine.

I'm very sure Sync would not be ok to implement, seeing as this type uses a RefCell for internal mutabilty (therefore any thread/task could call update simultaneously).

Am I understanding your description correctly that the point is that your API would ensure that for any given Rc it’d only ever be possible to send all of its copies at once to a different thread?

1 Like

That's correct.

The Rcs are only used by this type internally to create an interior-mutable tree structure. The Rcs will never be cloned after initialisation, but will of course be dropped when the type is dropped.

Drop will also update the reference counts, so that collective Send is important.

This is fuzzy though -- you have no guarantees about that implementation behavior.

I think I would just use Arc and not worry about it.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.