local lanes = require 'lanes'.configure() local msg = lanes.linda() local function volley(n,isa) print("Starting "..(isa and "A" or "B"), n) local rkey,skey = "a","b" if isa then skey,rkey = rkey,skey end msg:send("done",true) for i=1,n do local ball,value = msg:receive(rkey) msg:send(skey, value+1) end msg:send("done",true) end print("starting threads") local gen = lanes.gen("",volley) local N = 1e5 local a = gen(N, true) local b = gen(N) local ok,_ = msg:receive(0.5, msg.batched, "done", 2) if not ok then print "ouch" return end local t0 = os.time() msg:send("a", 0) msg:receive(nil, msg.batched, "done", 2) local t1 = os.time() print((t1-t0).." sec") print(((t1-t0)/N).." sec") print((N/(t1-t0)).." per sec")