COS226 - Lecture - Concurrent Objects - 3

COS226 - Lecture - Concurrent Objects - 3 - ● ...ensure...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
COS226: Concurrent Systems Chapter 3: Concurrent Objects – Part 3
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Java Memory Model Java does not guarantee linearizability or sequential consistency.
Background image of page 2
The Java Memory Model Java makes use of a relaxed memory model; Java satisfies a fundamental property: if a program's sequentially consistent executions follow certain rules then all executions of that program in the relaxed memory model will be sequentially consistent.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Java Memory Model Consider a Singleton: class Singleton { private static Singleton Instance; public static Singleton getInstance() { if (Instance == null) Instance = new Singleton(); return Instance; } }
Background image of page 4
The Java Memory Model Double-checked locking: if (Instance == null) { synchronized(Singleton.class) { if (Instance == null) Instance = new Singleton(); } } return Instance;
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Java Memory Model Shared memory vs Local Memory; Synchronization events; Synchronization events are linearizable.
Background image of page 6
Locks and Synchronization Blocks
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ● ...ensure that reads and writes to controlled fileds are linearizable. volatile Fields ● ...are linearizable; ● Reads and writes affect immediate memory synchronization; ● Mutual exclusion is still required; ● Useful for one writer, many readers. final Fields class FinalFieldExample { final int x, int y; static FinalFieldExample f; public FinalFieldExample() { x = 3; y = 4; } } final Fields static void writer() { f = new FinalFieldExample(); } static void reader() { if (f != null) { int i = f.x; int j = f.y; } } final Fields public class EventListener { final int x; public EventListener(\ EventSource eventSource) { eventSource.registerListener( this); } public onEvent(Event e) {} } Summary ● Reads and writes are linearizable if: ● the field is volatile; ● the field is protected by a unique lock that is acquired by all its readers and writers....
View Full Document

This note was uploaded on 10/11/2010 for the course COS COS226 taught by Professor Klazar during the Spring '10 term at University of Pretoria.

Page1 / 12

COS226 - Lecture - Concurrent Objects - 3 - ● ...ensure...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online