Concurrency en race condities
Concurrency en race condities
Concurrency en race condities
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
public class buffer {<br />
int store[];<br />
int filled;<br />
int empty;<br />
int readFrom;<br />
int writeTo;<br />
buffer (int size){<br />
empty = size;<br />
filled = 0;<br />
store = new int[size];<br />
readFrom = 0;<br />
writeTo = 0;<br />
}<br />
En nu in Java<br />
public synchronized void write(int value)<br />
{<br />
while (empty == 0){<br />
try { wait(); }<br />
catch(InterruptedException e) {<br />
System.err.println(e.toString());<br />
}<br />
}<br />
store[writeTo] = value;<br />
writeTo++;<br />
if (writeTo == (empty + filled))<br />
writeTo = 0;<br />
filled++;<br />
empty--;<br />
notifyAll();<br />
}<br />
College OS 2010 – 2011 40