{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

SYSC-3303-06-ConditionSynchronization

SYSC-3303-06-ConditionSynchronization - SYSC3303...

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

View Full Document Right Arrow Icon
SYSC 3303 Real Time Programming C diti S h i ti Condition Synchronization
Background image of page 1

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

View Full Document Right Arrow Icon
Task Synchronization Tasks – and especially threads – usually need to cooperate with each other in order to achieve a net goal. 1. Condition Synchronization Imposes order on joint execution sequence Allows one thread to perform an operation only after another thread has performed some other operation or has reached a defined state Objective: Delay a process until a condition is true 2. Mutual Exclusion Synchronization Controls access to shared resource. Objective: Ensure two processes do not interfere with each other’s use of a shared resource. 1/22/2009 SYSC 3303 Winter 2009 C. Schramm 2
Background image of page 2
Bounded Buffer Problem Classic Synchronization Problem Producer:Consumer share a finite buffer Accommodates differing rates of produce/consume Requires Mutex Synchronization on buffer contents Buffer operations are critical sections Condition Synchronization Producer must not add to full buffer Consumer must not remove from empty buffer Waiting threads must relinquish processor 1/22/2009 SYSC 3303 Winter 2009 C. Schramm 3
Background image of page 3

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

View Full Document Right Arrow Icon
Java Condition Synchronization Re visit stack: BoundedBuffer zip Re visit stack: BoundedBuffer.zip In Class Object wait() and wait(timeout) notify() and notifyAll() Used in conjunction with application’s condition Used in conjunction with application s condition variable Can only be called within synchronized methods “The current thread must own this object's monitor .” 1/22/2009 SYSC 3303 Winter 2009 C. Schramm 4
Background image of page 4
Tips on Using Wait() if (!condition) try { wait(); } catch (InterruptedException e) {} while (!condition) { () } ( ) {} try { wait(); } catch (InterruptedException e) {} Preserves liveness Guarantees safety 1/22/2009 SYSC 3303 Winter 2009 C. Schramm 5
Background image of page 5

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

View Full Document Right Arrow Icon
notify() versus notifyAll()
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}