Commit 49282f9a authored by Mohamad Bashar Desoki's avatar Mohamad Bashar Desoki

Memory inconsistency

parent 2270cd63
......@@ -4,16 +4,10 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="c46989a2-1428-4d1f-9b45-864f22943ab6" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/Counter.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/RaceConditionExample.java" afterDir="false" />
<list default="true" id="c46989a2-1428-4d1f-9b45-864f22943ab6" name="Changes" comment="Thread interference">
<change afterPath="$PROJECT_DIR$/src/main/java/MemoryConsistencyErrorExample.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -46,7 +40,14 @@
"SHARE_PROJECT_CONFIGURATION_FILES": "true"
}
}]]></component>
<component name="RunManager">
<component name="RunManager" selected="Application.MemoryConsistencyErrorExample">
<configuration name="MemoryConsistencyErrorExample" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="MemoryConsistencyErrorExample" />
<module name="Synchronization" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="RaceConditionExample" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="RaceConditionExample" />
<module name="Synchronization" />
......@@ -56,6 +57,7 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.MemoryConsistencyErrorExample" />
<item itemvalue="Application.RaceConditionExample" />
</list>
</recent_temporary>
......@@ -69,6 +71,14 @@
<option name="presentableId" value="Default" />
<updated>1699638681976</updated>
</task>
<task id="LOCAL-00001" summary="Thread interference">
<created>1699642277693</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1699642277693</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
......@@ -82,4 +92,8 @@
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Thread interference" />
<option name="LAST_COMMIT_MESSAGE" value="Thread interference" />
</component>
</project>
\ No newline at end of file
......@@ -4,6 +4,7 @@
* Thread Synchronization
* Race Condition
* Critical Section
* Memory inconsistency
*
* Locks and Atomic Variables
......
public class MemoryConsistencyErrorExample {
private static boolean sayHello = false;
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread(() -> {
while(!sayHello) {
}
System.out.println("Hello World!");
while(sayHello) {
}
System.out.println("Good Bye!");
});
thread.start();
Thread.sleep(1000);
System.out.println("Say Hello..");
sayHello = true;
Thread.sleep(1000);
System.out.println("Say Bye..");
sayHello = false;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment