SYSC-3303-05-Synchronization

SYSC-3303-05-Synchronization - SYSC 3303 RealTime...

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

View Full Document Right Arrow Icon
SYSC 3303 Real Time Programming hread Synchronization Thread Synchronization Embedded Systems: Contemporary Design Tool A Contemporary Design Tool , Chapter 12, James Peckol
Background image of page 1

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

View Full DocumentRight Arrow Icon
sk Synchronization Task Synchronization Tasks–and especially threads – usually need to cooperate with each other in order to achieve a net p goal. 1. Condition Synchronization poses order on joint execution sequence Imposes order on joint execution sequence Allows one thread to perform an operation only after another thread has performed some other operation or as reached a defined ate 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/15/2009 SYSC 3303 Winter 2009 C. Schramm 2
Background image of page 2
ondition nchronization Condition Synchronization Objective: Delay or block a task until a condition is true, or a thread has reached a given state Example: Lab 2 :main() :Yappy :Sleepy <<new>> <<new>> start() start() rintln og) Delay or lock 1/15/2009 SYSC 3303 Winter 2009 C. Schramm 3 println(log) Block
Background image of page 3

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

View Full DocumentRight Arrow Icon
Join public class Main { atic ar g[]; class Yappy extends Thread { static char log[]; static int index; ublic atic void ain( ) { public void run() { for (int i=0;i<loops;i++){ .. public static void main(…) { index = 0; log = new char[10000]; ….. } } Thread t1,t2; t1 = new Yappy('1', 1000) } class Sleepy extends Thread t2 = new Sleepy('2', 100) t1.start(); t2.start(); { public void run() { for (int i=0;i<loops;i++){ t1.join(); t2.join(); ….. } } 1/15/2009 SYSC 3303 Winter 2009 C. Schramm 4 System. out.println("Log is " + s); } } }
Background image of page 4
Flags public class Main { atic ar g[]; class Yappy extends Thread { static char log[]; static int index; static boolean done ; public void run() { while (busy) { .. public static void main(…) { index = 0; g new ar[10000 ….. } Main. done=true; log = new char[10000]; new Yappy('1', 1000).start(); } } class Sleepy extends Thread new Sleepy('2', 100).start(); done = false; { public void run() { while (moreToDo) { while (! done ) {} System. out.println("Log is " + s); } …..
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/16/2009 for the course SYSC 3303 taught by Professor Shramp during the Spring '09 term at Carleton CA.

Page1 / 18

SYSC-3303-05-Synchronization - SYSC 3303 RealTime...

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

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