Skip to content
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

Add SccIndexTable #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add SccIndexTable #15

wants to merge 2 commits into from

Conversation

wvwwvwwv
Copy link

Add scc::HashIndex which is highly optimised for read-heavy workloads.

@arthurprs
Copy link

Out of curiosity (I haven't dug in the implementation) does IndexTable not guarantee reads will see a previous write? Asking because I saw Linearizability: HashIndex read operations are not linearizable. in the documentation.

@wvwwvwwv
Copy link
Author

wvwwvwwv commented Oct 17, 2024

@arthurprs That requires some understanding of the computer architecture and memory ordering semantics.

The C++/Rust memory ordering model does not define any kind of data freshness, so for instance,

  • initial state: v = 2.
  • time X: thread 1 - v.compare_exchange(2, 3, release)
  • time X + 1: thread 2 - v.load(acquire)

There is absolutely no guarantee that thread 2 at time X + 1 reads "3" according to the language specs.

However, it is true that most microarchitectures including X86 and AARCH64 guarantee data freshness after an RMW (like CAS) operation which happens in the cache coherency protocol level.

Linearizability: HashIndex read operations are not linearizable. <- it is about the C++/Rust memory ordering model and the HashIndex implementation.
-> Write operations of HashIndex can be epitomised by "thread 1 - v.compare_exchange(2, 3, release)".
-> Lock-free read operations of HashIndex are basically "thread 2 - v.load(acquire)".

This implies that, in theory, readers are not guaranteed to observe the latest state of the HashIndex instance, because the C++/Rust memory model lacks a data freshness guarantee, however in reality, readers observe the latest state of the HashIndex, because the hardware "usually" guarantees it.

In short, HashIndex operations are linearizable on X86 and AARCH64.

@arthurprs
Copy link

I'm fairly sure most threaded code in the wild assumes an acquire load will see the outcome of a previous release write. But I see your point that it's not guaranteed all the way.

@wvwwvwwv
Copy link
Author

wvwwvwwv commented Oct 17, 2024

Right, that is a common misbelief; v.load(acquire) is modelled as load -> acquire fence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants