No. Two threads each add one to counter, yet it only grows by one.
From Operating Systems: Three Easy Pieces, chapters 4 to 28 (selected)
Art: Kurisu Makise from Steins;Gate © MAGES. / Nitroplus. Art: Project Neural Cloud (demo only). Credits
Tap a stop to see what it covers
Concept 1 of 1
When two threads run counter = counter + 1 and get interleaved between the load and the store, one update is lost. Code that touches shared data like this is a critical section, and it needs mutual exclusion.
p. 75p. 76p. 79
Operating Systems: Three Easy Pieces
pages.cs.wisc.edu/~remzi/OSTEP/License: Free online edition (author-hosted)
Every reel line that states a fact quotes this material with a page number. Tap the source button on any reel to read the quote.
Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau, free online edition at pages.cs.wisc.edu/~remzi/OSTEP.