From 9311cb23edc6557bf6151a24c41d9eb2ce69799a Mon Sep 17 00:00:00 2001
From: Andrew Myers When is synchronization needed?
do not propagate immediately to main memory or to the caches of other processors.
For example, consider
two threads executing the following code in parallel. Say the values of x
and y
-are initially 0.
+are initially 0. The idea is for Thread 2 to wait until Thread 1 finishes some work. It
+signals that it is done by setting the variable x
to 1:
Thread 1:
@@ -576,11 +577,12 @@ When is synchronization needed?Thread 2 could observe the update tox before the update to y .
The fact that Thread 1 assigned to y before
it assigned 1 to x does not matter! This behavior can and does happen frequently
-with modern hardware. When it happens is hardware-dependent, so that code that seems to work
-correctly on one processor (say, an Intel x86 processor) may fail to work on a machine using
-an ARM processor. This bizarre state of affairs shows that programming with
-concurrency can be highly counterintuitive, and that one must never rely on naive assumptions
-about the order of events.
+with modern hardware. When it happens is hardware-dependent, so that code that
+seems to work correctly on one processor (say, an Intel x86 processor) may fail
+to work on a machine using an ARM processor, which makes weaker guarantees.
+This bizarre state of affairs shows that programming with concurrency can be
+highly counterintuitive, and that it is easy to make bad assumptions about the
+order of events.
The most reliable way diff --git a/lectures/synchronization/index.html b/lectures/synchronization/index.html index 82913c1..4dd8477 100644 --- a/lectures/synchronization/index.html +++ b/lectures/synchronization/index.html @@ -124,6 +124,7 @@ Condition variablesGiven that synchronization is needed for threads to see each other's effects, is there a way to successfully implement the earlier example that broke due to weak memory consistency? +Recall that the idea was to have one thread wait until another one finished some updates: |