Hacker News new | ask | show | jobs
by winstonprivacy 1095 days ago
Ok, interesting and all but just tell me how I can get 1 ns cross thread access to variables in C++
2 comments

Ok, that's the latency of the L1 cache and that isn't shared between threads, so you might not want to count on being able to do this.
Exactly. I was referring to that bit at the end of the article:

"In the case of Java volatiles, part of the solution is to force all reads/writes to bypass the local registers, and immediately trigger cache reads/writes instead. As soon as the data is read/written to the L1 cache, the hardware-coherency protocol takes over and provides guaranteed coherency across all global threads. Thus ensuring that if multiple threads are reading/writing to the same variable, they are all kept in sync with one another. And this is how you can achieve inter-thread coordination in as little as 1ns."

That last sentence can be pedantically true, if you look at in a very strict context. It doesn't say the variable can be returned in 1ns - but even if it did, it says the inter-thread coordination can take place in "as little as" 1ns. If a L1 cache immediately returning it's cached value for a memory address because it has the data in E or M state, that's technically a form of inter-thread coordination, just using already-coordinated state.
Ok, but why are you asking how to do it? They are saying how to do it, even though it's nonsense.
I don't know the answer, but I'm sure it involves the use of some FTL solution.