Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Synchronous-concurrency/Zkl/synchronous-concurrency.zkl
Normal file
15
Task/Synchronous-concurrency/Zkl/synchronous-concurrency.zkl
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
fcn reader(fileName,out){
|
||||
n:=0; foreach line in (File(fileName)) { out.write(line); n+=1; }
|
||||
out.close(); // signal done
|
||||
Atomic.waitFor(out.Property("isOpen")); // wait for other thread to reopen Pipe
|
||||
out.write(n);
|
||||
}
|
||||
fcn writer(in){
|
||||
Utils.zipWith(fcn(n,line){ "%3d: %s".fmt(n,line).print() },[1..],in);
|
||||
in.open(); // signal other thread to send num lines read
|
||||
println("Other thread read ",in.read()," lines");
|
||||
}
|
||||
|
||||
p:=Thread.Pipe(); // NOT Unix pipes, thread safe channel between threads
|
||||
reader.launch("input.txt",p);
|
||||
writer.future(p).noop(); // noop forces eval, ie sleep until writer finished
|
||||
Loading…
Add table
Add a link
Reference in a new issue