29.2 Shared Data
Each thread has its own stack. This means local variables and function parameters belong to it and only it. Another thread does not get to see them and, above all, cannot change them.
Global variables and heap memory are shared among all threads. If one thread changes a global variable, then another thread will notice—but when is hard to say.
Within a thread, it is guaranteed that one statement happens after the next. This may sound trivial, but it is not. I want to remind you of Chapter 4, because what applies to statements does not apply to expressions: In func(a(), b()) it is not specified that a() is executed before b() (or vice versa). Only from statement to statement is there a guarantee that operations between them ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access