I have created two threads, one each for addition and subtraction. I want them to run simultaneously, what are the possible ways for achieving concurrency?
Code Select
function onScriptLoad()
{
local coro1 = newthread(add);
local coro2 = newthread(sub);
local addition=coro1.call(0);
local subtraction=coro2.call(50);
local i=1;
do
{
print("suspend passed ("+addition+")\n");
print("suspend passed ("+subtraction+")\n");
if(coro1.getstatus()=="suspended")
addition= coro1.wakeup("Addition started "+i);
if(coro2.getstatus()=="suspended")
subtraction= coro2.wakeup("Subtraction started "+i);
++i;
}while(coro1.getstatus()=="suspended"||coro2.getstatus()=="suspended");
}
x <- 0;
y <- 50;
function add(x)
{
while(x<50)
{
x=x+5;
print(x);
if(x==25)
local ret = suspend("addition suspended");
}
}
function sub(y)
{
while(y>0)
{
y=y-5;
print(y);
if(y==25)
local ret = suspend("subtraction suspended");
}
}