K
K
kolomRus2021-05-21 12:57:00
Multithreading
kolomRus, 2021-05-21 12:57:00

Allocation of cache memory between threads?

Breaking a few articles, I realized that each core has its own cache and I just can’t understand how the cache memory is distributed between threads and do threads see changes in cache variables if they are executed in the same core?
Suppose there are 2 threads that are executed alternately on the same core, how do they share the cache of this core?
What happens if the variable is not synchronized or marked as volatile , and these two threads, which run on the same core, increment this variable?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-05-21
@kolomRus

Break a few articles, I realized that each core has its own cache

Multiple caches. Moreover, some of the caches can be shared between several cores.
What happens if the variable is not synchronized or marked as volatile

Unpredictable behavior will depend on the specific hardware and a bunch of other factors.
Therefore, based on the two previous points, it is better not to go to the iron level if you are not writing a driver, but to operate with the corresponding high-level models of the programming language and runtime environment. Especially since volatile solves more than just visibility problems .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question