Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Private copy of data from shared location

I'm at the moment reading Concurrent Programming on Windows by Joe Duffy, and came across the following statement:

Multiple threads make private copies of data from a shared location

This statement was given after an example where Joe showed how incrementing a global variable from multiple threads could lead to unpredictable results, because they could overlap in time.

However I remain skeptic about the statement, since there's no such thing as a private copy of a atomic data type - that would make it non-atomic.

So when he says make private copies of data from a shared location is it then simply all non-atomic data types (user-defined types, etc.) he means, or have I missed something?

like image 736
ebb Avatar asked Jan 01 '26 00:01

ebb


1 Answers

Since I don't have the book on hands, I can only guess he's talking about how processors execute code.

There is no scape from transferring data to a CPU register because this is the only way a CPU instruction can access it. So, in this sense, every time a thread uses data from a shared location a temporary private copy has to be made.

like image 179
Thomas C. G. de Vilhena Avatar answered Jan 02 '26 14:01

Thomas C. G. de Vilhena



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!