ExProCon


code

pworkers = 10;
cworkers = 10;
count = 10;
bsize = 10;
res = 0;

BoundedBuffer buf[bsize];

con i = 1 to pworkers do
  Producuer(i);
end

con i = 1 to cworkers do
  Consumer(i);
end

Producer(i) {
  for i = 1 to count do
    put i in buf;
  end
}

Consumer(i) {
  s = 0;
  for i = 1 to count do
    get val from buf;
    s += val;
  end

  atomic res += s; end
}

java source code