wvwwvwwv / scalable-concurrent-containers

High performance containers and utilities for concurrent and asynchronous programming
Apache License 2.0
285 stars 14 forks source link

how to use AtomicShared when Ptr is not send #126

Closed beckend closed 2 months ago

beckend commented 5 months ago

I am trying to integrate AtomicShared in my codebase, however creating an async function and spawning it in a thread is impossible when Ptr is !Send.

wvwwvwwv commented 5 months ago

Unfortunately, Ptr can never be Send since it relies on its thread-local storage to pin the referenced instance in memory; that's what epoch-based reclamation is for: same applies to Guard.

In order to send a reference to the data, you'll have to make Shared out of AtomicShared through AtomicShared::get_shared. Shared holds a strong reference to the instance, so it can be sent across threads and awaits.

Hope this explanation helps you!

wvwwvwwv commented 5 months ago

In short, Ptr and Guard cannot be sent across await and spawn.

beckend commented 5 months ago

Please add more examples in the examples folder.

wvwwvwwv commented 5 months ago

I'll enhance the examples, but you'll be able to find a lot of resources on the internet for crossbeam_epoch. scc::ebr is a subset of crossbeam_epoch (though the implementation is substantially different) + reference counting for easier use.

wvwwvwwv commented 2 months ago

Updated examples in https://github.com/wvwwvwwv/scalable-delayed-dealloc/