Concurrent Programming
|
|
|
- Derek Cameron
- 10 years ago
- Views:
Transcription
1 Concurrent Programming Shared Memory Passing the baton Monitors Verónica Gaspes CERES, November 2, 2007 ceres
2 Outline 1 Recap 2 Readers & Writers Readers & writers (mutual exclusion) Readers & writers (conditions) A programming technique: Passing the baton 3 Monitors Monitors in the real world... Syntax and Semantics Java Readers & Writers revisited
3 Concurrent programming Programs with many parts (processes, threads) that could be executed at the same time! Shared memory The processes build one program by using some shared variables that they all can read and modify. The processes might need to use some of the variables in mutual exclusion, wait for the variables to have values satisfying some condition. Distributed The processes build one program by sharing some communication mechanism a mailbox or a telephone line
4 Concurrent programming Programs with many parts (processes, threads) that could be executed at the same time! Shared memory The processes build one program by using some shared variables that they all can read and modify. The processes might need to use some of the variables in mutual exclusion, wait for the variables to have values satisfying some condition. Distributed The processes build one program by sharing some communication mechanism a mailbox or a telephone line
5 Concurrent programming Programs with many parts (processes, threads) that could be executed at the same time! Shared memory The processes build one program by using some shared variables that they all can read and modify. The processes might need to use some of the variables in mutual exclusion, wait for the variables to have values satisfying some condition. Distributed The processes build one program by sharing some communication mechanism a mailbox or a telephone line
6 Concurrent programming Programs with many parts (processes, threads) that could be executed at the same time! Shared memory The processes build one program by using some shared variables that they all can read and modify. The processes might need to use some of the variables in mutual exclusion, wait for the variables to have values satisfying some condition. Distributed The processes build one program by sharing some communication mechanism a mailbox or a telephone line
7 Concurrent programming Programs with many parts (processes, threads) that could be executed at the same time! Shared memory The processes build one program by using some shared variables that they all can read and modify. The processes might need to use some of the variables in mutual exclusion, wait for the variables to have values satisfying some condition. Distributed The processes build one program by sharing some communication mechanism a mailbox or a telephone line
8 Concurrent programming Programs with many parts (processes, threads) that could be executed at the same time! Shared memory The processes build one program by using some shared variables that they all can read and modify. The processes might need to use some of the variables in mutual exclusion, wait for the variables to have values satisfying some condition. Distributed The processes build one program by sharing some communication mechanism a mailbox or a telephone line
9 Concurrent programming Programs with many parts (processes, threads) that could be executed at the same time! Shared memory The processes build one program by using some shared variables that they all can read and modify. The processes might need to use some of the variables in mutual exclusion, wait for the variables to have values satisfying some condition. Distributed The processes build one program by sharing some communication mechanism a mailbox or a telephone line
10 Concurrent programming Programs with many parts (processes, threads) that could be executed at the same time! Shared memory The processes build one program by using some shared variables that they all can read and modify. The processes might need to use some of the variables in mutual exclusion, wait for the variables to have values satisfying some condition. Distributed The processes build one program by sharing some communication mechanism a mailbox or a telephone line
11 Processes in MPD resource A # specification part body A() process a[i = 1 to 10]{... process... end b{... The parts a[1],..., a[10], b and the rest of the instructions in the body are executed concurrently. resource A # specification part body A()... co p() // q() oc... co [i = 1 to 10] {r(i) oc end p, q and r(i) are ordinary functions.
12 Processes in MPD resource A # specification part body A() process a[i = 1 to 10]{... process... end b{... The parts a[1],..., a[10], b and the rest of the instructions in the body are executed concurrently. resource A # specification part body A()... co p() // q() oc... co [i = 1 to 10] {r(i) oc end p, q and r(i) are ordinary functions.
13 Processes in MPD resource A # specification part body A() process a[i = 1 to 10]{... process... end b{... The parts a[1],..., a[10], b and the rest of the instructions in the body are executed concurrently. resource A # specification part body A()... co p() // q() oc... co [i = 1 to 10] {r(i) oc end p, q and r(i) are ordinary functions.
14 Processes in MPD resource A # specification part body A() process a[i = 1 to 10]{... process... end b{... The parts a[1],..., a[10], b and the rest of the instructions in the body are executed concurrently. resource A # specification part body A()... co p() // q() oc... co [i = 1 to 10] {r(i) oc end p, q and r(i) are ordinary functions.
15 Processes in MPD resource A # specification part body A() process a[i = 1 to 10]{... process... end b{... The parts a[1],..., a[10], b and the rest of the instructions in the body are executed concurrently. resource A # specification part body A()... co p() // q() oc... co [i = 1 to 10] {r(i) oc end p, q and r(i) are ordinary functions.
16 Threads in Java class A{... public static void main(string[] cmndln){... new T1().start(); new T2().start();... class T1 implements Runnable { public void run(){... class T2 extends Thread { public void run(){...
17 Threads in Java class A{... public static void main(string[] cmndln){... new T1().start(); new T2().start();... class T1 implements Runnable { public void run(){... class T2 extends Thread { public void run(){...
18 Threads in Java class A{... public static void main(string[] cmndln){... new T1().start(); new T2().start();... class T1 implements Runnable { public void run(){... class T2 extends Thread { public void run(){...
19 Threads in Java class A{... public static void main(string[] cmndln){... new T1().start(); new T2().start();... class T1 implements Runnable { public void run(){... class T2 extends Thread { public void run(){...
20 Semaphores Languages that provide ways to describe processes provide also ways to synchronize the processes. One such mechanism for shared memory is semaphores. Mutual Exclusion Processes share a semaphore, say mutex with initial value 1 follow the protocol P(mutex) #exclusive V(mutex) Wait on conditions Identify the conditions, possibly introduce variables to express them, follow the technique called passing the baton! It is important to follow working techniques because it is impossible to debug concurrent programs!
21 Semaphores Languages that provide ways to describe processes provide also ways to synchronize the processes. One such mechanism for shared memory is semaphores. Mutual Exclusion Processes share a semaphore, say mutex with initial value 1 follow the protocol P(mutex) #exclusive V(mutex) Wait on conditions Identify the conditions, possibly introduce variables to express them, follow the technique called passing the baton! It is important to follow working techniques because it is impossible to debug concurrent programs!
22 Semaphores Languages that provide ways to describe processes provide also ways to synchronize the processes. One such mechanism for shared memory is semaphores. Mutual Exclusion Processes share a semaphore, say mutex with initial value 1 follow the protocol P(mutex) #exclusive V(mutex) Wait on conditions Identify the conditions, possibly introduce variables to express them, follow the technique called passing the baton! It is important to follow working techniques because it is impossible to debug concurrent programs!
23 Readers & Writers - why? A problem with selective mutual exclusion (as opposed to critical sections!) One solution based on mutual exclusion synchronization that has fairness problems : writers might starve. Another solution based on condition synchronization that illustrates a general programming technique: passing the baton. Both solutions use semaphores.
24 Readers & Writers - why? A problem with selective mutual exclusion (as opposed to critical sections!) One solution based on mutual exclusion synchronization that has fairness problems : writers might starve. Another solution based on condition synchronization that illustrates a general programming technique: passing the baton. Both solutions use semaphores.
25 Readers & Writers - why? A problem with selective mutual exclusion (as opposed to critical sections!) One solution based on mutual exclusion synchronization that has fairness problems : writers might starve. Another solution based on condition synchronization that illustrates a general programming technique: passing the baton. Both solutions use semaphores.
26 Readers & Writers - why? A problem with selective mutual exclusion (as opposed to critical sections!) One solution based on mutual exclusion synchronization that has fairness problems : writers might starve. Another solution based on condition synchronization that illustrates a general programming technique: passing the baton. Both solutions use semaphores.
27 Readers & Writers - problem statement Two kinds of processes (Readers and Writers) share a database. Readers execute transactions that examine database records. Writers execute transactions that both examine and update database records. The database is consistent initially and transactions, if performed in isolation, preserve consistency. A writer must have exclusive access to the database. Assuming no writer is using the database, any number of readers may concurrently execute transactions.
28 Readers & Writers - problem statement Two kinds of processes (Readers and Writers) share a database. Readers execute transactions that examine database records. Writers execute transactions that both examine and update database records. The database is consistent initially and transactions, if performed in isolation, preserve consistency. A writer must have exclusive access to the database. Assuming no writer is using the database, any number of readers may concurrently execute transactions.
29 Readers & Writers - problem statement Two kinds of processes (Readers and Writers) share a database. Readers execute transactions that examine database records. Writers execute transactions that both examine and update database records. The database is consistent initially and transactions, if performed in isolation, preserve consistency. A writer must have exclusive access to the database. Assuming no writer is using the database, any number of readers may concurrently execute transactions.
30 Readers & Writers - problem statement Two kinds of processes (Readers and Writers) share a database. Readers execute transactions that examine database records. Writers execute transactions that both examine and update database records. The database is consistent initially and transactions, if performed in isolation, preserve consistency. A writer must have exclusive access to the database. Assuming no writer is using the database, any number of readers may concurrently execute transactions.
31 Readers & Writers - problem statement Two kinds of processes (Readers and Writers) share a database. Readers execute transactions that examine database records. Writers execute transactions that both examine and update database records. The database is consistent initially and transactions, if performed in isolation, preserve consistency. A writer must have exclusive access to the database. Assuming no writer is using the database, any number of readers may concurrently execute transactions.
32 Readers & Writers - problem statement Two kinds of processes (Readers and Writers) share a database. Readers execute transactions that examine database records. Writers execute transactions that both examine and update database records. The database is consistent initially and transactions, if performed in isolation, preserve consistency. A writer must have exclusive access to the database. Assuming no writer is using the database, any number of readers may concurrently execute transactions.
33 R&W - mutual exclusion First overconstrain the solution: treat it as critical sections. Then relax the constraints so that readers can execute concurrently: Only the first reader has to grab the lock to the database; only the last reader has to release the lock. We need a shared variable to count the number of readers accessing the database! sem rw = 1 process Reader[i = 1 to M]{ while(true){ P(rw) # read! V(rw) process Writer[j = 1 to N]{ while(true){ P(rw) # write! V(rw)
34 R&W - mutual exclusion First overconstrain the solution: treat it as critical sections. Then relax the constraints so that readers can execute concurrently: Only the first reader has to grab the lock to the database; only the last reader has to release the lock. We need a shared variable to count the number of readers accessing the database! sem rw = 1 process Reader[i = 1 to M]{ while(true){ P(rw) # read! V(rw) process Writer[j = 1 to N]{ while(true){ P(rw) # write! V(rw)
35 R&W - mutual exclusion First overconstrain the solution: treat it as critical sections. Then relax the constraints so that readers can execute concurrently: Only the first reader has to grab the lock to the database; only the last reader has to release the lock. We need a shared variable to count the number of readers accessing the database! sem rw = 1 process Reader[i = 1 to M]{ while(true){ P(rw) # read! V(rw) process Writer[j = 1 to N]{ while(true){ P(rw) # write! V(rw)
36 R&W - mutual exclusion First overconstrain the solution: treat it as critical sections. Then relax the constraints so that readers can execute concurrently: Only the first reader has to grab the lock to the database; only the last reader has to release the lock. We need a shared variable to count the number of readers accessing the database! sem rw = 1 process Reader[i = 1 to M]{ while(true){ P(rw) # read! V(rw) process Writer[j = 1 to N]{ while(true){ P(rw) # write! V(rw)
37 R&W - mutual exclusion sem rw = 1 # lock to the database sem mutexr = 1 # lock to the counter of readers int nr = 0 # counter of readers process Reader[i = 1 to m] while(true) P(mutexR) nr = nr+1 if(nr == 1){P(rw) V(mutexR) # read! P(mutexR) nr = nr-1 if (nr == 0){V(rw) V(mutexR) process Writer[j = 1 to n] while(true) P(rw) # write! V(rw) Once a reader gets access, writers might starve: as long as new readers arrive writers have to wait!
38 R&W - mutual exclusion sem rw = 1 # lock to the database sem mutexr = 1 # lock to the counter of readers int nr = 0 # counter of readers process Reader[i = 1 to m] while(true) P(mutexR) nr = nr+1 if(nr == 1){P(rw) V(mutexR) # read! P(mutexR) nr = nr-1 if (nr == 0){V(rw) V(mutexR) process Writer[j = 1 to n] while(true) P(rw) # write! V(rw) Once a reader gets access, writers might starve: as long as new readers arrive writers have to wait!
39 R&W - mutual exclusion sem rw = 1 # lock to the database sem mutexr = 1 # lock to the counter of readers int nr = 0 # counter of readers process Reader[i = 1 to m] while(true) P(mutexR) nr = nr+1 if(nr == 1){P(rw) V(mutexR) # read! P(mutexR) nr = nr-1 if (nr == 0){V(rw) V(mutexR) process Writer[j = 1 to n] while(true) P(rw) # write! V(rw) Once a reader gets access, writers might starve: as long as new readers arrive writers have to wait!
40 R&W - mutual exclusion sem rw = 1 # lock to the database sem mutexr = 1 # lock to the counter of readers int nr = 0 # counter of readers process Reader[i = 1 to m] while(true) P(mutexR) nr = nr+1 if(nr == 1){P(rw) V(mutexR) # read! P(mutexR) nr = nr-1 if (nr == 0){V(rw) V(mutexR) process Writer[j = 1 to n] while(true) P(rw) # write! V(rw) Once a reader gets access, writers might starve: as long as new readers arrive writers have to wait!
41 R&W - conditions Count the number of readers and the number of writers trying to access the database and constrain the values of the counters. Let nr and nw be nonnegative integers recording the number of readers and the number of writers accessing the database. The following condition should be true for all states: Good States (nr == 0 and nw <= 1) or nw == 0
42 R&W - conditions Count the number of readers and the number of writers trying to access the database and constrain the values of the counters. Let nr and nw be nonnegative integers recording the number of readers and the number of writers accessing the database. The following condition should be true for all states: Good States (nr == 0 and nw <= 1) or nw == 0
43 R&W - conditions Count the number of readers and the number of writers trying to access the database and constrain the values of the counters. Let nr and nw be nonnegative integers recording the number of readers and the number of writers accessing the database. The following condition should be true for all states: Good States (nr == 0 and nw <= 1) or nw == 0
44 A skeleton int nr = 0, nw = 0 process Reader[i = 1 to m] while(true) #ATOMIC: await (nw==0) # read! #ATOMIC: nr = nr-1 then nr = nr+1 process Writer[j = 1 to n] while(true) #ATOMIC: await (nr==0 and nw==0) then nw = nw+1 # write! #ATOMIC: nw=nw-1
45 Implementing waiting on conditions Passing the baton When a process is executing within a critical section, think of it as holding a baton that means Permission to execute. When a process has done what it was waiting to do it passes the baton to one other process: If some process is waiting for a condition that is now true, the baton is passed to one such process. When no process is waiting on a condition that is true, the baton is passed to the next process that tries to enter the critical section.
46 Implementing waiting on conditions Passing the baton When a process is executing within a critical section, think of it as holding a baton that means Permission to execute. When a process has done what it was waiting to do it passes the baton to one other process: If some process is waiting for a condition that is now true, the baton is passed to one such process. When no process is waiting on a condition that is true, the baton is passed to the next process that tries to enter the critical section.
47 Implementing waiting on conditions Passing the baton When a process is executing within a critical section, think of it as holding a baton that means Permission to execute. When a process has done what it was waiting to do it passes the baton to one other process: If some process is waiting for a condition that is now true, the baton is passed to one such process. When no process is waiting on a condition that is true, the baton is passed to the next process that tries to enter the critical section.
48 Implementing waiting on conditions Passing the baton When a process is executing within a critical section, think of it as holding a baton that means Permission to execute. When a process has done what it was waiting to do it passes the baton to one other process: If some process is waiting for a condition that is now true, the baton is passed to one such process. When no process is waiting on a condition that is true, the baton is passed to the next process that tries to enter the critical section.
49 Implementing waiting on conditions Passing the baton When a process is executing within a critical section, think of it as holding a baton that means Permission to execute. When a process has done what it was waiting to do it passes the baton to one other process: If some process is waiting for a condition that is now true, the baton is passed to one such process. When no process is waiting on a condition that is true, the baton is passed to the next process that tries to enter the critical section.
50 Implementing atomic waiting on conditions Use a semaphore to control entry into each atomic statement: sem e = 1 Associate a semaphore with each condition and count the number of delayed processes on each semaphore: sem r = 0; int dr = 0 sem w = 0; int dw = 0
51 Implementing atomic waiting on conditions await (nw==0) then nr = nr+1 P(e) if (nw > 0){dr=dr+1; V(e); P(r) nr = nr+1 if(dr>0) {dr=dr-1;v(r) else {V(e)
52 Implementing atomic waiting on conditions await (nw==0) then nr = nr+1 P(e) if (nw > 0){dr=dr+1; V(e); P(r) nr = nr+1 if(dr>0) {dr=dr-1;v(r) else {V(e)
53 Implementing atomic waiting on conditions nr = nr-1 P(e) nr = nr-1 if(nr==0 and dw>0) {dw=dw-1;v(w) else {V(e)
54 Implementing atomic waiting on conditions nr = nr-1 P(e) nr = nr-1 if(nr==0 and dw>0) {dw=dw-1;v(w) else {V(e)
55 Implementing atomic waiting on conditions await (nr == 0 and nw==0) then nw = nw+1 P(e) if (nr > 0 or nw > 0){dw=dw+1; V(e); P(w) nw = nw+1 V(e)
56 Implementing atomic waiting on conditions await (nr == 0 and nw==0) then nw = nw+1 P(e) if (nr > 0 or nw > 0){dw=dw+1; V(e); P(w) nw = nw+1 V(e)
57 Implementing atomic waiting on conditions P(e) nw = nw-1 if(dr>0) {dr=dr-1;v(r) elseif(dw>0){dw=dw-1;v(w) else {V(e) nw = nw-1
58 Implementing atomic waiting on conditions P(e) nw = nw-1 if(dr>0) {dr=dr-1;v(r) elseif(dw>0){dw=dw-1;v(w) else {V(e) nw = nw-1
59 Lizards
60 Recap Screens Readers & Writers Monitors
61 Submarines
62 A language approach to synchronization
63 An Abstract Data Type... Example class Counter{ private int x = 0; Example resource Counter op inc() body Counter() public void inc(){ int tmp = x; Support.nap(10); tmp++; Support.nap(10); x = tmp; int x = 0 proc inc(){ int tmp = x nap(10);tmp++;nap(10) x = tmp end
64 An Abstract Data Type... Example class Counter{ private int x = 0; Example resource Counter op inc() body Counter() public void inc(){ int tmp = x; Support.nap(10); tmp++; Support.nap(10); x = tmp; int x = 0 proc inc(){ int tmp = x nap(10);tmp++;nap(10) x = tmp end
65 An Abstract Data Type... Example class Counter{ private int x = 0; Example resource Counter op inc() body Counter() public void inc(){ int tmp = x; Support.nap(10); tmp++; Support.nap(10); x = tmp; int x = 0 proc inc(){ int tmp = x nap(10);tmp++;nap(10) x = tmp end
66 ... that supports Mutual Exclusion Example import java.util.concurrency.locks.*; class Counter{ private final Lock lock = new ReentrantLock(); private int x = 0; public void inc(){ lock.lock(); try{ int tmp = x; Support.nap(10); tmp++; Support.nap(10); x = tmp; finally{lock.unlock();
67 ... that supports Mutual Exclusion Example resource Counter op inc() body Counter() sem mutex = 1 int x = 0 proc inc(){ P(mutex) int tmp = x nap(10);tmp++;nap(10) x = tmp V(mutex) end
68 What does this mean? The abstract data type can be shared by many threads while preserving the integrity of the representation! Only one thread at a time is allowed to be using the monitor. All other threads are blocked until they can be given permission to enter. Example cap Counter c = create Counter() process Turnstile[p = 1 to nroft]{ while(true){ c.inc() nap(int(floor(random()*100)))
69 What does this mean? The abstract data type can be shared by many threads while preserving the integrity of the representation! Only one thread at a time is allowed to be using the monitor. All other threads are blocked until they can be given permission to enter. Example cap Counter c = create Counter() process Turnstile[p = 1 to nroft]{ while(true){ c.inc() nap(int(floor(random()*100)))
70 What does this mean? The abstract data type can be shared by many threads while preserving the integrity of the representation! Only one thread at a time is allowed to be using the monitor. All other threads are blocked until they can be given permission to enter. Example cap Counter c = create Counter() process Turnstile[p = 1 to nroft]{ while(true){ c.inc() nap(int(floor(random()*100)))
71 What does this mean? The abstract data type can be shared by many threads while preserving the integrity of the representation! Only one thread at a time is allowed to be using the monitor. All other threads are blocked until they can be given permission to enter. Example cap Counter c = create Counter() process Turnstile[p = 1 to nroft]{ while(true){ c.inc() nap(int(floor(random()*100)))
72 What does this mean? The abstract data type can be shared by many threads while preserving the integrity of the representation! Only one thread at a time is allowed to be using the monitor. All other threads are blocked until they can be given permission to enter. Example cap Counter c = create Counter() process Turnstile[p = 1 to nroft]{ while(true){ c.inc() nap(int(floor(random()*100)))
73 And support for Condition Synchronization With more elaborate abstract data types, threads might need to be blocked until some condition holds for the abstract datatype. Example In the bounded buffer that is shared by producer threads and consumer threads: Producers might have to wait until the buffer is not full. Consumers might have to wait until the buffer is not empty. Languages supporting monitors provide a type for condition variables. We first discuss their purpose and expected operations. Then we look at Java. Then we do an example.
74 And support for Condition Synchronization With more elaborate abstract data types, threads might need to be blocked until some condition holds for the abstract datatype. Example In the bounded buffer that is shared by producer threads and consumer threads: Producers might have to wait until the buffer is not full. Consumers might have to wait until the buffer is not empty. Languages supporting monitors provide a type for condition variables. We first discuss their purpose and expected operations. Then we look at Java. Then we do an example.
75 And support for Condition Synchronization With more elaborate abstract data types, threads might need to be blocked until some condition holds for the abstract datatype. Example In the bounded buffer that is shared by producer threads and consumer threads: Producers might have to wait until the buffer is not full. Consumers might have to wait until the buffer is not empty. Languages supporting monitors provide a type for condition variables. We first discuss their purpose and expected operations. Then we look at Java. Then we do an example.
76 And support for Condition Synchronization With more elaborate abstract data types, threads might need to be blocked until some condition holds for the abstract datatype. Example In the bounded buffer that is shared by producer threads and consumer threads: Producers might have to wait until the buffer is not full. Consumers might have to wait until the buffer is not empty. Languages supporting monitors provide a type for condition variables. We first discuss their purpose and expected operations. Then we look at Java. Then we do an example.
77 And support for Condition Synchronization With more elaborate abstract data types, threads might need to be blocked until some condition holds for the abstract datatype. Example In the bounded buffer that is shared by producer threads and consumer threads: Producers might have to wait until the buffer is not full. Consumers might have to wait until the buffer is not empty. Languages supporting monitors provide a type for condition variables. We first discuss their purpose and expected operations. Then we look at Java. Then we do an example.
78 Monitors offer Condition Variables Used to Delay a process that cannot safely continue executing until the monitor s state satisfies some property. How? Awaken a delayed process when the property holds. 1 Inside a monitor declare a variable of the type for condition variables cond cv. 2 A process blocks on a condition variable by executing wait(cv). 3 Processes that are blocked on condition variables get awaken by signal(cv).
79 Monitors offer Condition Variables Used to Delay a process that cannot safely continue executing until the monitor s state satisfies some property. How? Awaken a delayed process when the property holds. 1 Inside a monitor declare a variable of the type for condition variables cond cv. 2 A process blocks on a condition variable by executing wait(cv). 3 Processes that are blocked on condition variables get awaken by signal(cv).
80 Monitors offer Condition Variables Used to Delay a process that cannot safely continue executing until the monitor s state satisfies some property. How? Awaken a delayed process when the property holds. 1 Inside a monitor declare a variable of the type for condition variables cond cv. 2 A process blocks on a condition variable by executing wait(cv). 3 Processes that are blocked on condition variables get awaken by signal(cv).
81 Monitors offer Condition Variables Used to Delay a process that cannot safely continue executing until the monitor s state satisfies some property. How? Awaken a delayed process when the property holds. 1 Inside a monitor declare a variable of the type for condition variables cond cv. 2 A process blocks on a condition variable by executing wait(cv). 3 Processes that are blocked on condition variables get awaken by signal(cv).
82 Monitors offer Condition Variables Used to Delay a process that cannot safely continue executing until the monitor s state satisfies some property. How? Awaken a delayed process when the property holds. 1 Inside a monitor declare a variable of the type for condition variables cond cv. 2 A process blocks on a condition variable by executing wait(cv). 3 Processes that are blocked on condition variables get awaken by signal(cv).
83 Monitors offer Condition Variables Used to Delay a process that cannot safely continue executing until the monitor s state satisfies some property. How? Awaken a delayed process when the property holds. 1 Inside a monitor declare a variable of the type for condition variables cond cv. 2 A process blocks on a condition variable by executing wait(cv). 3 Processes that are blocked on condition variables get awaken by signal(cv).
84 Monitors offer Condition Variables Used to Delay a process that cannot safely continue executing until the monitor s state satisfies some property. How? Awaken a delayed process when the property holds. 1 Inside a monitor declare a variable of the type for condition variables cond cv. 2 A process blocks on a condition variable by executing wait(cv). 3 Processes that are blocked on condition variables get awaken by signal(cv).
85 Semantics Values The value of a condition variable is a queue of delayed processes. Wait The process that executes wait(cv) gets delayed at the rear of the queue for cv. It relinquishes exclusive access to the monitor. Signal Execution of signal(cv) examines cv s queue. If it is empty it has no effect. If there are delayed porcesses, it awakens the process at the front of the queue.
86 Semantics Values The value of a condition variable is a queue of delayed processes. Wait The process that executes wait(cv) gets delayed at the rear of the queue for cv. It relinquishes exclusive access to the monitor. Signal Execution of signal(cv) examines cv s queue. If it is empty it has no effect. If there are delayed porcesses, it awakens the process at the front of the queue.
87 Semantics Values The value of a condition variable is a queue of delayed processes. Wait The process that executes wait(cv) gets delayed at the rear of the queue for cv. It relinquishes exclusive access to the monitor. Signal Execution of signal(cv) examines cv s queue. If it is empty it has no effect. If there are delayed porcesses, it awakens the process at the front of the queue.
88 Semantics Values The value of a condition variable is a queue of delayed processes. Wait The process that executes wait(cv) gets delayed at the rear of the queue for cv. It relinquishes exclusive access to the monitor. Signal Execution of signal(cv) examines cv s queue. If it is empty it has no effect. If there are delayed porcesses, it awakens the process at the front of the queue.
89 Semantics - signaling disciplines Who will get to run when a process does signal(cv)? The signaling process? The newly awaken process? Signal and Continue The signaler continues, the signaled process executes at some later time. Signal and Wait The signaler waits until some other time and the signaled process executes now. Signal and Continue is implemented in Unix, Java and PThreads. It is compatible with priority scheduling, programs are easier to understand.
90 Semantics - signaling disciplines Who will get to run when a process does signal(cv)? The signaling process? The newly awaken process? Signal and Continue The signaler continues, the signaled process executes at some later time. Signal and Wait The signaler waits until some other time and the signaled process executes now. Signal and Continue is implemented in Unix, Java and PThreads. It is compatible with priority scheduling, programs are easier to understand.
91 Semantics - signaling disciplines Who will get to run when a process does signal(cv)? The signaling process? The newly awaken process? Signal and Continue The signaler continues, the signaled process executes at some later time. Signal and Wait The signaler waits until some other time and the signaled process executes now. Signal and Continue is implemented in Unix, Java and PThreads. It is compatible with priority scheduling, programs are easier to understand.
92 Semantics - signaling disciplines Who will get to run when a process does signal(cv)? The signaling process? The newly awaken process? Signal and Continue The signaler continues, the signaled process executes at some later time. Signal and Wait The signaler waits until some other time and the signaled process executes now. Signal and Continue is implemented in Unix, Java and PThreads. It is compatible with priority scheduling, programs are easier to understand.
93 What we don t see...
94 java.util.concurrent.locks Monitors (locks and condition types) are provided in the package java.util.concurrent.locks The interface Condition Conditions (also known as condition queues or condition variables) provide a means for one thread to suspend execution (to wait ) until notified by another thread that some state condition may now be true. Because access to this shared state information occurs in different threads, it must be protected, so a lock of some form is associated with the condition. The key property that waiting for a condition provides is that it atomically releases the associated lock and suspends the current thread.
95 java.util.concurrent.locks Monitors (locks and condition types) are provided in the package java.util.concurrent.locks The interface Condition Conditions (also known as condition queues or condition variables) provide a means for one thread to suspend execution (to wait ) until notified by another thread that some state condition may now be true. Because access to this shared state information occurs in different threads, it must be protected, so a lock of some form is associated with the condition. The key property that waiting for a condition provides is that it atomically releases the associated lock and suspends the current thread.
96 java.util.concurrent.locks A Condition instance is intrinsically bound to a lock. To obtain a Condition instance for a particular Lock instance use its newcondition() method. Example class BoundedBuffer<T>{ private Lock lock = new ReentrantLock(); private Condition notfull = lock.newcondition(); private Condition notempty = lock.newcondition(); private int count = 0; private int n; private T[] buf; private int front = 0; private int rear = 0;...
97 java.util.concurrent.locks A Condition instance is intrinsically bound to a lock. To obtain a Condition instance for a particular Lock instance use its newcondition() method. Example class BoundedBuffer<T>{ private Lock lock = new ReentrantLock(); private Condition notfull = lock.newcondition(); private Condition notempty = lock.newcondition(); private int count = 0; private int n; private T[] buf; private int front = 0; private int rear = 0;...
98 Using Condition Example public void deposit(t item){ lock.lock(); try{ while(count == n) notfull.await(); buf[rear] = item; rear = inc(rear); count++; notempty.signal(); catch(interruptedexception e){ System.out.println(e.getMessage()); finally{ lock.unlock();
99 Using Condition Example public T fetch(){ lock.lock(); try{ while(count == 0) notempty.await(); T result = buf[front]; front = inc(front); count--; notfull.signal(); return result; catch(interruptedexception e){ System.out.println(e.getMessage());return null; finally{ lock.unlock();
100 Scheduling readers and writers The scheduler has 2 roles: Schedule requests. Ensure that no writer is using the database when readers are using it. Ensure that only one writer at a time uses the database.
101 Scheduling readers and writers The scheduler has 2 roles: Schedule requests. Ensure that no writer is using the database when readers are using it. Ensure that only one writer at a time uses the database.
102 Scheduling readers and writers The scheduler has 2 roles: Schedule requests. Ensure that no writer is using the database when readers are using it. Ensure that only one writer at a time uses the database.
103 Scheduling readers and writers The scheduler has 2 roles: Schedule requests. Ensure that no writer is using the database when readers are using it. Ensure that only one writer at a time uses the database.
104 Scheduling readers and writers The scheduler has 2 roles: Schedule requests. Ensure that no writer is using the database when readers are using it. Ensure that only one writer at a time uses the database.
105 Scheduling readers and writers The scheduler has 2 roles: Schedule requests. Ensure that no writer is using the database when readers are using it. Ensure that only one writer at a time uses the database.
106 Scheduling readers and writers The scheduler has 2 roles: Schedule requests. Ensure that no writer is using the database when readers are using it. Ensure that only one writer at a time uses the database.
107 Scheduling readers and writers Writers have to follow 1 Request permission to write 2 Write 3 Release the database Readers have to follow 1 Request permission to read 2 Read 3 Release the database
108 Scheduling readers and writers Writers have to follow 1 Request permission to write 2 Write 3 Release the database Readers have to follow 1 Request permission to read 2 Read 3 Release the database
109 Scheduling readers and writers Writers have to follow 1 Request permission to write 2 Write 3 Release the database Readers have to follow 1 Request permission to read 2 Read 3 Release the database
110 Scheduling readers and writers Writers have to follow 1 Request permission to write 2 Write 3 Release the database Readers have to follow 1 Request permission to read 2 Read 3 Release the database
111 Scheduling readers and writers Writers have to follow 1 Request permission to write 2 Write 3 Release the database Readers have to follow 1 Request permission to read 2 Read 3 Release the database
112 Scheduling readers and writers Writers have to follow 1 Request permission to write 2 Write 3 Release the database Readers have to follow 1 Request permission to read 2 Read 3 Release the database
113 Scheduling readers and writers Writers have to follow 1 Request permission to write 2 Write 3 Release the database Readers have to follow 1 Request permission to read 2 Read 3 Release the database
114 Scheduling readers and writers Writers have to follow 1 Request permission to write 2 Write 3 Release the database Readers have to follow 1 Request permission to read 2 Read 3 Release the database
115 Scheduling readers and writers Writers have to follow 1 Request permission to write 2 Write 3 Release the database Readers have to follow 1 Request permission to read 2 Read 3 Release the database
116 Scheduling readers and writers Writers have to follow 1 Request permission to write 2 Write 3 Release the database Readers have to follow 1 Request permission to read 2 Read 3 Release the database
117 Scheduling readers and writers Writers have to follow 1 Request permission to write 2 Write 3 Release the database Readers have to follow 1 Request permission to read 2 Read 3 Release the database
118 Organizing the program in Java import java.util.concurrent.locks.*; class RWScheduler{ public void requestread() public void requestwrite() public void releaseread() public void releasewrite()
119 Organizing the program in Java class Reader extends Thread{ private RWScheduler rws; private DB db; public Reader(int id, RWScheduler rws, DB db){ this.rws = rws; this.db = db; public void run(){ while(true){ rws.requestread(); db.read(); rws.releaseread();
120 Organizing the program in Java class Writer extends Thread{ private RWScheduler rws; private DB db; public Writer(int id, RWScheduler rws, DB db){ this.rws = rws; this.db = db; public void run(){ while(true){ rws.requestwrite(); db.write(...); rws.releasewrite();
121 How do we program the scheduler? The scheduler has to delay readers and/or writers until they have the right to use the database. For doing so, it counts the number of readers and number of writers using the db. The scheduler has to wake up readers and/or writers following some policy. For doing so, it counts the number of delayed readers and writers.
122 How do we program the scheduler? The scheduler has to delay readers and/or writers until they have the right to use the database. For doing so, it counts the number of readers and number of writers using the db. The scheduler has to wake up readers and/or writers following some policy. For doing so, it counts the number of delayed readers and writers.
123 Scheduler code import java.util.concurrent.locks.*; class RWScheduler{ private int nr = 0; private int nw = 0; private int dr = 0; private int dw = 0; private ReentrantLock lock = new ReentrantLock(); private Condition reader = lock.newcondition(); private Condition writer = lock.newcondition();
124 Scheduler code requestread import java.util.concurrent.locks.*; class RWScheduler{ public void requestread(){ lock.lock(); try{ while(nw > 0) {dr++;reader.await(); nr++; if(nr==1){dr=0;reader.signalall(); catch(interruptedexception e){ finally{lock.unlock(); Can writers starve?
125 Scheduler code releaseread import java.util.concurrent.locks.*; class RWScheduler{ public void releaseread(){ lock.lock(); try{ nr--; if(nr==0 && dw>0){dw--;writer.signal(); finally{lock.unlock();
126 Scheduler code requestwrite import java.util.concurrent.locks.*; class RWScheduler{ public void requestwrite(){ lock.lock(); try{ while(nw > 0 nr >0) {dw++;writer.await(); nw++; catch(interruptedexception e){ finally{lock.unlock();
127 Scheduler code releasewrite import java.util.concurrent.locks.*; class RWScheduler{ public void releasewrite(){ lock.lock(); try{ nw--; if(dr>0){dr--;reader.signal(); else{dw--;writer.signal(); finally{lock.unlock();
Monitors, Java, Threads and Processes
Monitors, Java, Threads and Processes 185 An object-oriented view of shared memory A semaphore can be seen as a shared object accessible through two methods: wait and signal. The idea behind the concept
Semaphores and Monitors: High-level Synchronization Constructs
Semaphores and Monitors: High-level Synchronization Constructs 1 Synchronization Constructs Synchronization Coordinating execution of multiple threads that share data structures Past few lectures: Locks:
Monitors & Condition Synchronization
Chapter 5 Monitors & Condition Synchronization 1 monitors & condition synchronization Concepts: monitors: encapsulated data + access procedures mutual exclusion + condition synchronization nested monitors
Outline of this lecture G52CON: Concepts of Concurrency
Outline of this lecture G52CON: Concepts of Concurrency Lecture 10 Synchronisation in Java Natasha Alechina School of Computer Science [email protected] mutual exclusion in Java condition synchronisation
! Past few lectures: Ø Locks: provide mutual exclusion Ø Condition variables: provide conditional synchronization
1 Synchronization Constructs! Synchronization Ø Coordinating execution of multiple threads that share data structures Semaphores and Monitors: High-level Synchronization Constructs! Past few lectures:
Lecture 6: Semaphores and Monitors
HW 2 Due Tuesday 10/18 Lecture 6: Semaphores and Monitors CSE 120: Principles of Operating Systems Alex C. Snoeren Higher-Level Synchronization We looked at using locks to provide mutual exclusion Locks
4. Monitors. Monitors support data encapsulation and information hiding and are easily adapted to an object-oriented environment.
4. Monitors Problems with semaphores: - shared variables and the semaphores that protect them are global variables - Operations on shared variables and semaphores distributed throughout program - difficult
Last Class: Semaphores
Last Class: Semaphores A semaphore S supports two atomic operations: S Wait(): get a semaphore, wait if busy semaphore S is available. S Signal(): release the semaphore, wake up a process if one is waiting
Chapter 6 Concurrent Programming
Chapter 6 Concurrent Programming Outline 6.1 Introduction 6.2 Monitors 6.2.1 Condition Variables 6.2.2 Simple Resource Allocation with Monitors 6.2.3 Monitor Example: Circular Buffer 6.2.4 Monitor Example:
Lecture 6: Introduction to Monitors and Semaphores
Concurrent Programming 19530-V (WS01) Lecture 6: Introduction to Monitors and Semaphores Dr. Richard S. Hall [email protected] Concurrent programming November 27, 2001 Abstracting Locking Details
Chapter 8 Implementing FSP Models in Java
Chapter 8 Implementing FSP Models in Java 1 8.1.1: The Carpark Model A controller is required for a carpark, which only permits cars to enter when the carpark is not full and does not permit cars to leave
Concurrent programming in Java
Concurrent programming in Java INF4140 04.10.12 Lecture 5 0 Book: Andrews - ch.05 (5.4) Book: Magee & Kramer ch.04 - ch.07 INF4140 (04.10.12) Concurrent programming in Java Lecture 5 1 / 33 Outline 1 Monitors:
3C03 Concurrency: Condition Synchronisation
3C03 Concurrency: Condition Synchronisation Mark Handley 1 Goals n Introduce concepts of Condition synchronisation Fairness Starvation n Modelling: Relationship between guarded actions and condition synchronisation?
Monitors and Semaphores
Monitors and Semaphores Annotated Condition Variable Example Condition *cv; Lock* cvmx; int waiter = 0; await() { cvmx->lock(); waiter = waiter + 1; /* I m sleeping */ cv->wait(cvmx); /* sleep */ cvmx->unlock();
Mutual Exclusion using Monitors
Mutual Exclusion using Monitors Some programming languages, such as Concurrent Pascal, Modula-2 and Java provide mutual exclusion facilities called monitors. They are similar to modules in languages that
Java Memory Model: Content
Java Memory Model: Content Memory Models Double Checked Locking Problem Java Memory Model: Happens Before Relation Volatile: in depth 16 March 2012 1 Java Memory Model JMM specifies guarantees given by
SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I)
SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I) Shan He School for Computational Science University of Birmingham Module 06-19321: SSC Outline Outline of Topics
CS11 Java. Fall 2014-2015 Lecture 7
CS11 Java Fall 2014-2015 Lecture 7 Today s Topics! All about Java Threads! Some Lab 7 tips Java Threading Recap! A program can use multiple threads to do several things at once " A thread can have local
COS 318: Operating Systems. Semaphores, Monitors and Condition Variables
COS 318: Operating Systems Semaphores, Monitors and Condition Variables Prof. Margaret Martonosi Computer Science Department Princeton University http://www.cs.princeton.edu/courses/archive/fall11/cos318/
Java Concurrency Framework. Sidartha Gracias
Java Concurrency Framework Sidartha Gracias Executive Summary This is a beginners introduction to the java concurrency framework Some familiarity with concurrent programs is assumed However the presentation
Parallel Programming
Parallel Programming 0024 Recitation Week 7 Spring Semester 2010 R 7 :: 1 0024 Spring 2010 Today s program Assignment 6 Review of semaphores Semaphores Semaphoren and (Java) monitors Semaphore implementation
6 Synchronization with Semaphores
32 6 Synchronization with Semaphores The too-much-milk solution is much too complicated. The problem is that the mutual exclusion mechanism was too simple-minded: it used only atomic reads and writes.
Hoare-Style Monitors for Java
Hoare-Style Monitors for Java Theodore S Norvell Electrical and Computer Engineering Memorial University February 17, 2006 1 Hoare-Style Monitors Coordinating the interactions of two or more threads can
Shared Address Space Computing: Programming
Shared Address Space Computing: Programming Alistair Rendell See Chapter 6 or Lin and Synder, Chapter 7 of Grama, Gupta, Karypis and Kumar, and Chapter 8 of Wilkinson and Allen Fork/Join Programming Model
Real Time Programming: Concepts
Real Time Programming: Concepts Radek Pelánek Plan at first we will study basic concepts related to real time programming then we will have a look at specific programming languages and study how they realize
Resurrecting Ada s Rendez-Vous in Java
Resurrecting Ada s Rendez-Vous in Java Luis Mateu, José M. Piquer and Juan León DCC - Universidad de Chile Casilla 2777, Santiago, Chile [email protected] Abstract Java is a programming language designed
Design Patterns in C++
Design Patterns in C++ Concurrency Patterns Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa May 4, 2011 G. Lipari (Scuola Superiore Sant Anna) Concurrency Patterns May 4,
Thread Synchronization and the Java Monitor
Articles News Weblogs Buzz Chapters Forums Table of Contents Order the Book Print Email Screen Friendly Version Previous Next Chapter 20 of Inside the Java Virtual Machine Thread Synchronization by Bill
Distributed Systems [Fall 2012]
Distributed Systems [Fall 2012] [W4995-2] Lec 6: YFS Lab Introduction and Local Synchronization Primitives Slide acks: Jinyang Li, Dave Andersen, Randy Bryant (http://www.news.cs.nyu.edu/~jinyang/fa10/notes/ds-lec2.ppt,
JAVA - MULTITHREADING
JAVA - MULTITHREADING http://www.tutorialspoint.com/java/java_multithreading.htm Copyright tutorialspoint.com Java is amulti threaded programming language which means we can develop multi threaded program
Threads & Tasks: Executor Framework
Threads & Tasks: Executor Framework Introduction & Motivation WebServer Executor Framework Callable and Future 12 April 2012 1 Threads & Tasks Motivations for using threads Actor-based Goal: Create an
Intel TSX (Transactional Synchronization Extensions) Mike Dai Wang and Mihai Burcea
Intel TSX (Transactional Synchronization Extensions) Mike Dai Wang and Mihai Burcea 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Example: toy banking application with RTM Code written and tested in
Built-in Concurrency Primitives in Java Programming Language. by Yourii Martiak and Mahir Atmis
Built-in Concurrency Primitives in Java Programming Language by Yourii Martiak and Mahir Atmis Overview One of the many strengths of Java is the built into the programming language support for concurrency
3 - Lift with Monitors
3 - Lift with Monitors TSEA81 - Computer Engineering and Real-time Systems This document is released - 2015-11-24 version 1.4 Author - Ola Dahl, Andreas Ehliar Assignment - 3 - Lift with Monitors Introduction
A Survey of Parallel Processing in Linux
A Survey of Parallel Processing in Linux Kojiro Akasaka Computer Science Department San Jose State University San Jose, CA 95192 408 924 1000 [email protected] ABSTRACT Any kernel with parallel processing
Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 SOLUTIONS.
Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 Name: SOLUTIONS Athena* User Name: Instructions This quiz is 50 minutes long. It contains
Lecture 8: Safety and Liveness Properties
Concurrent Programming 19530-V (WS01) 1 Lecture 8: Safety and Liveness Properties Dr. Richard S. Hall [email protected] Concurrent programming December 11, 2001 Safety Properties 2 A safety property
Chapter 6, The Operating System Machine Level
Chapter 6, The Operating System Machine Level 6.1 Virtual Memory 6.2 Virtual I/O Instructions 6.3 Virtual Instructions For Parallel Processing 6.4 Example Operating Systems 6.5 Summary Virtual Memory General
Concurrent Programming
Concurrent Programming Principles and Practice Gregory R. Andrews The University of Arizona Technische Hochschule Darmstadt FACHBEREICH INFCRMATIK BIBLIOTHEK Inventar-Nr.:..ZP.vAh... Sachgebiete:..?r.:..\).
MonitorExplorer: A State Exploration-Based Approach to Testing Java Monitors
Department of Computer Science and Engineering University of Texas at Arlington Arlington, TX 76019 MonitorExplorer: A State Exploration-Based Approach to Testing Java Monitors Y. Lei, R. Carver, D. Kung,
Deadlock Victim. dimanche 6 mai 12
Deadlock Victim by Dr Heinz Kabutz && Olivier Croisier The Java Specialists Newsletter && The Coder's Breakfast [email protected] && [email protected] 1 You discover a race condition 2
Crash Course in Java
Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is
Overview. CMSC 330: Organization of Programming Languages. Synchronization Example (Java 1.5) Lock Interface (Java 1.5) ReentrantLock Class (Java 1.
CMSC 330: Organization of Programming Languages Java 1.5, Ruby, and MapReduce Overview Java 1.5 ReentrantLock class Condition interface - await( ), signalall( ) Ruby multithreading Concurrent programming
Monitor Object. An Object Behavioral Pattern for Concurrent Programming. Douglas C. Schmidt
Monitor Object An Object Behavioral Pattern for Concurrent Programming Douglas C. Schmidt [email protected] Department of Computer Science Washington University, St. Louis 1 Intent The Monitor Object
SYSTEM ecos Embedded Configurable Operating System
BELONGS TO THE CYGNUS SOLUTIONS founded about 1989 initiative connected with an idea of free software ( commercial support for the free software ). Recently merged with RedHat. CYGNUS was also the original
Resource Utilization of Middleware Components in Embedded Systems
Resource Utilization of Middleware Components in Embedded Systems 3 Introduction System memory, CPU, and network resources are critical to the operation and performance of any software system. These system
Operating Systems and Networks
recap Operating Systems and Networks How OS manages multiple tasks Virtual memory Brief Linux demo Lecture 04: Introduction to OS-part 3 Behzad Bordbar 47 48 Contents Dual mode API to wrap system calls
Concurrency Control: Locking, Optimistic, Degrees of Consistency
CS262A: Advanced Topics in Computer Systems Joe Hellerstein, Spring 2008 UC Berkeley Concurrency Control: Locking, Optimistic, Degrees of Consistency Transaction Refresher Statement of problem: Database:
Creating a Simple, Multithreaded Chat System with Java
Creating a Simple, Multithreaded Chat System with Java Introduction by George Crawford III In this edition of Objective Viewpoint, you will learn how to develop a simple chat system. The program will demonstrate
OPERATING SYSTEMS PROCESS SYNCHRONIZATION
OPERATING SYSTEMS PROCESS Jerry Breecher 6: Process Synchronization 1 OPERATING SYSTEM Synchronization What Is In This Chapter? This is about getting processes to coordinate with each other. How do processes
Understanding Hardware Transactional Memory
Understanding Hardware Transactional Memory Gil Tene, CTO & co-founder, Azul Systems @giltene 2015 Azul Systems, Inc. Agenda Brief introduction What is Hardware Transactional Memory (HTM)? Cache coherence
Resource Reservation & Resource Servers. Problems to solve
Resource Reservation & Resource Servers Problems to solve Hard-deadline tasks may be Periodic or Sporadic (with a known minimum arrival time) or Non periodic (how to deal with this?) Soft-deadline tasks
Introduction to Database Management Systems
Database Administration Transaction Processing Why Concurrency Control? Locking Database Recovery Query Optimization DB Administration 1 Transactions Transaction -- A sequence of operations that is regarded
W4118 Operating Systems. Instructor: Junfeng Yang
W4118 Operating Systems Instructor: Junfeng Yang Outline Introduction to scheduling Scheduling algorithms 1 Direction within course Until now: interrupts, processes, threads, synchronization Mostly mechanisms
OBJECT ORIENTED PROGRAMMING LANGUAGE
UNIT-6 (MULTI THREADING) Multi Threading: Java Language Classes The java.lang package contains the collection of base types (language types) that are always imported into any given compilation unit. This
First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
Threads 1. When writing games you need to do more than one thing at once.
Threads 1 Threads Slide 1 When writing games you need to do more than one thing at once. Threads offer a way of automatically allowing more than one thing to happen at the same time. Java has threads as
Overview Motivating Examples Interleaving Model Semantics of Correctness Testing, Debugging, and Verification
Introduction Overview Motivating Examples Interleaving Model Semantics of Correctness Testing, Debugging, and Verification Advanced Topics in Software Engineering 1 Concurrent Programs Characterized by
Tuple spaces and Object spaces. Distributed Object Systems 12. Tuple spaces and Object spaces. Communication. Tuple space. Mechanisms 2.
Distributed Object Systems 12 Tuple spaces and Object spaces Tuple spaces and Object spaces Tuple spaces Shared memory as a mechanism for exchanging data in a distributed setting (i.e. separate from processes)
Computer Science 483/580 Concurrent Programming Midterm Exam February 23, 2009
Computer Science 483/580 Concurrent Programming Midterm Exam February 23, 2009 Your name There are 6 pages to this exam printed front and back. Please make sure that you have all the pages now. The exam
Linux Driver Devices. Why, When, Which, How?
Bertrand Mermet Sylvain Ract Linux Driver Devices. Why, When, Which, How? Since its creation in the early 1990 s Linux has been installed on millions of computers or embedded systems. These systems may
Middleware. Peter Marwedel TU Dortmund, Informatik 12 Germany. technische universität dortmund. fakultät für informatik informatik 12
Universität Dortmund 12 Middleware Peter Marwedel TU Dortmund, Informatik 12 Germany Graphics: Alexandra Nolte, Gesine Marwedel, 2003 2010 年 11 月 26 日 These slides use Microsoft clip arts. Microsoft copyright
TESTING JAVA MONITORS BY STATE SPACE EXPLORATION MONICA HERNANDEZ. Presented to the Faculty of the Graduate School of
TESTING JAVA MONITORS BY STATE SPACE EXPLORATION by MONICA HERNANDEZ Presented to the Faculty of the Graduate School of The University of Texas at Arlington in Partial Fulfillment of the Requirements for
Topics. Producing Production Quality Software. Concurrent Environments. Why Use Concurrency? Models of concurrency Concurrency in Java
Topics Producing Production Quality Software Models of concurrency Concurrency in Java Lecture 12: Concurrent and Distributed Programming Prof. Arthur P. Goldberg Fall, 2005 2 Why Use Concurrency? Concurrent
e ag u g an L g ter lvin v E ram Neal G g ro va P Ja
Evolving the Java Programming Language Neal Gafter Overview The Challenge of Evolving a Language Design Principles Design Goals JDK7 and JDK8 Challenge: Evolving a Language What is it like trying to extend
Tasks Schedule Analysis in RTAI/Linux-GPL
Tasks Schedule Analysis in RTAI/Linux-GPL Claudio Aciti and Nelson Acosta INTIA - Depto de Computación y Sistemas - Facultad de Ciencias Exactas Universidad Nacional del Centro de la Provincia de Buenos
Introduction to SPIN. Acknowledgments. Parts of the slides are based on an earlier lecture by Radu Iosif, Verimag. Ralf Huuck. Features PROMELA/SPIN
Acknowledgments Introduction to SPIN Parts of the slides are based on an earlier lecture by Radu Iosif, Verimag. Ralf Huuck Ralf Huuck COMP 4152 1 Ralf Huuck COMP 4152 2 PROMELA/SPIN PROMELA (PROcess MEta
Between Mutual Trust and Mutual Distrust: Practical Fine-grained Privilege Separation in Multithreaded Applications
Between Mutual Trust and Mutual Distrust: Practical Fine-grained Privilege Separation in Multithreaded Applications Jun Wang, Xi Xiong, Peng Liu Penn State Cyber Security Lab 1 An inherent security limitation
Real-Time Component Software. slide credits: H. Kopetz, P. Puschner
Real-Time Component Software slide credits: H. Kopetz, P. Puschner Overview OS services Task Structure Task Interaction Input/Output Error Detection 2 Operating System and Middleware Applica3on So5ware
Figure 30.1: A Parent Waiting For Its Child What we would like to see here is the following output:
30 Condition Variables Thus far we have developed the notion of a lock and seen how one can be properly built with the right combination of hardware and OS support. Unfortunately, locks are not the only
OS: IPC I. Cooperating Processes. CIT 595 Spring 2010. Message Passing vs. Shared Memory. Message Passing: Unix Pipes
Cooperating Processes Independent processes cannot affect or be affected by the execution of another process OS: IPC I CIT 595 Spring 2010 Cooperating process can affect or be affected by the execution
Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6
Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6 Winter Term 2008 / 2009 Jun.-Prof. Dr. André Brinkmann [email protected] Universität Paderborn PC² Agenda Multiprocessor and
Linux Scheduler. Linux Scheduler
or or Affinity Basic Interactive es 1 / 40 Reality... or or Affinity Basic Interactive es The Linux scheduler tries to be very efficient To do that, it uses some complex data structures Some of what it
Outline. Review. Inter process communication Signals Fork Pipes FIFO. Spotlights
Outline Review Inter process communication Signals Fork Pipes FIFO Spotlights 1 6.087 Lecture 14 January 29, 2010 Review Inter process communication Signals Fork Pipes FIFO Spotlights 2 Review: multithreading
Understanding the Python GIL
Understanding the Python GIL David Beazley http://www.dabeaz.com Presented at PyCon 2010 Atlanta, Georgia 1 Introduction As a few of you might know, C Python has a Global Interpreter Lock (GIL) >>> import
Operating System: Scheduling
Process Management Operating System: Scheduling OS maintains a data structure for each process called Process Control Block (PCB) Information associated with each PCB: Process state: e.g. ready, or waiting
Java Virtual Machine Locks
Java Virtual Machine Locks SS 2008 Synchronized Gerald SCHARITZER (e0127228) 2008-05-27 Synchronized 1 / 13 Table of Contents 1 Scope...3 1.1 Constraints...3 1.2 In Scope...3 1.3 Out of Scope...3 2 Logical
Course Development of Programming for General-Purpose Multicore Processors
Course Development of Programming for General-Purpose Multicore Processors Wei Zhang Department of Electrical and Computer Engineering Virginia Commonwealth University Richmond, VA 23284 [email protected]
The Oracle Universal Server Buffer Manager
The Oracle Universal Server Buffer Manager W. Bridge, A. Joshi, M. Keihl, T. Lahiri, J. Loaiza, N. Macnaughton Oracle Corporation, 500 Oracle Parkway, Box 4OP13, Redwood Shores, CA 94065 { wbridge, ajoshi,
Programming real-time systems with C/C++ and POSIX
Programming real-time systems with C/C++ and POSIX Michael González Harbour 1. Introduction The C language [1], developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories, is the most widely
A Comparison Of Shared Memory Parallel Programming Models. Jace A Mogill David Haglin
A Comparison Of Shared Memory Parallel Programming Models Jace A Mogill David Haglin 1 Parallel Programming Gap Not many innovations... Memory semantics unchanged for over 50 years 2010 Multi-Core x86
Hadoop Fair Scheduler Design Document
Hadoop Fair Scheduler Design Document October 18, 2010 Contents 1 Introduction 2 2 Fair Scheduler Goals 2 3 Scheduler Features 2 3.1 Pools........................................ 2 3.2 Minimum Shares.................................
The Little Book of Semaphores
The Little Book of Semaphores Allen B. Downey Version 2.1.2 2 The Little Book of Semaphores Second Edition Version 2.1.2 Copyright 2005, 2006, 2007 Allen B. Downey Permission is granted to copy, distribute
Paper 3F6: Software Engineering and Systems Distributed Systems Design Solutions to Examples Paper 3
Engineering Tripos Part IIA THIRD YEAR Paper 3F: Software Engineering and Systems Distributed Systems Design Solutions to Examples Paper 3 CORBA 1. (a) A typical IDL file for this application is as follows:
ODROID Multithreading in Android
Multithreading in Android 1 Index Android Overview Android Stack Android Development Tools Main Building Blocks(Activity Life Cycle) Threading in Android Multithreading via AsyncTask Class Multithreading
Information Management
Information Management Dr Marilyn Rose McGee-Lennon [email protected] What is Information Management about Aim: to understand the ways in which databases contribute to the management of large amounts
Kernel Synchronization and Interrupt Handling
Kernel Synchronization and Interrupt Handling Oliver Sengpie, Jan van Esdonk Arbeitsbereich Wissenschaftliches Rechnen Fachbereich Informatik Fakultt fr Mathematik, Informatik und Naturwissenschaften Universitt
Embedded Systems. 6. Real-Time Operating Systems
Embedded Systems 6. Real-Time Operating Systems Lothar Thiele 6-1 Contents of Course 1. Embedded Systems Introduction 2. Software Introduction 7. System Components 10. Models 3. Real-Time Models 4. Periodic/Aperiodic
