3 ms·
There are exceptions to this rule--i.e. there are ways to not really be thread-safe but to have things work anyway--but they fall in the category of "you have t
by pcwalton 11y ago
There are exceptions to this rule--i.e. there are ways to not really be thread-safe but to have things work anyway--but they fall in the category of "you have to really, really know your CPU and be willing to write processor-specific code that just happens to work", so you can basically ignore them.
My favorite is the libdispatch abuse of cpuid to flood the pipeline on Intel CPUs for this problem: https://www.mikeash.com/pyblog/friday-qa-2014-06-06-secrets-of-dispatch_once.html https://www.mikeash.com/pyblog/friday-qa-2014-06-06-secrets-...
But really, take Coda's advice. If you aren't synchronizing your reads, you can basically just assume your code is broken.
- twic 11y agoAn interesting exception is Lamport's Bakery: https://en.m.wikipedia.org/wiki/Lamport%27s_bakery_algorithm https://en.m.wikipedia.org/wiki/Lamport%27s_bakery_algorithm Thread safety without synchronisation primitives. I'm not sure it's ever actually a good idea to use it, though. EDIT: unless you count a fence as a synchronisation primitive.
- deleted 11y ago[deleted]