Skip to content

Arc<AllocatorContext> is never shared across threads #1474

@qinsoon

Description

@qinsoon

We currently use Arc for AllocatorContext. AllocatorContext is thread-local, but shared by multiple allocators in the same thread. Ideally we should use Rc for it.

However, we have allocators (including AllocatorContext) in mutators and GC workers. Our current API explicitly transfer GCWorker to a new thread, thus GCWorker is required to be Send. And whatever we use for AllocatorContext needs to be Send.

Rc is !Send. So we use Arc instead.


Rc is not Send. If it were Send, you could clone an Rc and send to another thread and the ref count would not be maintained correctly. However, for our case, we can always guarantee that all the Rc instances are sent at once, and all the Rc instances will not be used unless they are in the same thread. We could use something like https://crates.io/crates/sendable (which may be slower as they check that all the instances are from the same thread), or our own SendableRc type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions