14 lines
465 B
Plaintext
14 lines
465 B
Plaintext
var pipe=Thread.Pipe(); // used to connect the two threads
|
|
fcn{ while(1){ pipe.write((0.0).random(1.0)) } }.launch(); // generator
|
|
fcn{ // consumer/calculator
|
|
N:=0; M:=SD:=sum:=ssum:=0.0;
|
|
while(1){
|
|
x:=pipe.read(); N+=1; sum+=x; ssum+=x*x;
|
|
M=sum/N; SD=(ssum/N - M*M).sqrt();
|
|
if(0==N%100000)
|
|
println("N:%,10d mean:%.5f std dev:%.5f".fmt(N,M,SD));
|
|
}
|
|
}.launch();
|
|
|
|
Atomic.sleep(60*60); // wait because exiting the VM kills the threads
|