[ create a new paste ] login | about

Link: http://codepad.org/qf1Tf8j9    [ raw code | fork ]

D, pasted on Sep 2:
import core.thread;
import std.concurrency;
import std.stdio;

class Foo
{
    void test(int x) 
    {
        static int count;
        count += x;
        
        writeln(count);
    }
}

void main() 
{
    spawn(&test1);
    spawn(&test2);
}

void test1()
{
    auto foo = new Foo;
    foreach (i; 0 .. 1000)
    {
        foo.test(1);
        Thread.sleep(dur!("msecs")(50));
    }
}

void test2()
{
    auto foo = new Foo;
    foreach (i; 0 .. 1000)
    {
        foo.test(-1);
        Thread.sleep(dur!("msecs")(50));
    }    
}


Create a new paste based on this one


Comments: