Ali
Ali

Reputation: 443

Can false sharing lead to wrong results?

As I know, false sharing occurs when two cpu cores access different parts of a single memory block. In this case, the L1 caches in each core contains different values.

What is the effect of false sharing? Do commodity CPUs always detect a false sharing? Can it lead to something like a race condition (persisting different cache versions in the memory)?

Upvotes: 1

Views: 486

Answers (1)

Mike Seymour
Mike Seymour

Reputation: 254691

False sharing occurs when one core modifies some data, and another reads some unrelated data that happens to lie in the same cache line. The modification forces the second core to reload the whole cache line, even though the data it's using is unchanged.

This won't cause any incorrect behaviour unless the cache is horribly broken. But it can have a large performance impact, as cached data is unnecessarily fetched from higher level caches.

Upvotes: 8

Related Questions