lean2/tests/lua/threads/th2.lua
Leonardo de Moura eb9d0f0552 test(lua): add example showing how to access/update an environment object using multiple threads
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-11-11 20:53:23 -08:00

22 lines
397 B
Lua

S1 = State()
S2 = State()
code = [[
function f(env, prefix, num, type)
for i = 1, num do
env:add_var(prefix .. "_" .. i, type)
end
end
]]
S1:dostring(code)
S2:dostring(code)
e = environment()
e:add_var("N", Type())
code2 = [[
e, prefix = ...
f(e, prefix, 1000, Const("N"))
]]
T1 = thread(S1, code2, e, "x")
T2 = thread(S2, code2, e, "y")
T1:wait()
T2:wait()
print(e)