Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
unittest for fibers
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNowak committed May 29, 2011
1 parent 0a18e49 commit f7e7eae
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/core/thread.d
Expand Up @@ -3799,6 +3799,64 @@ private:
}
}

version( unittest )
{
class TestFiber : Fiber
{
this()
{
super(&run);
}

void run()
{
foreach(i; 0 .. 1000)
{
sum += i;
Fiber.yield();
}
}

size_t sum;
}

void runTen()
{
TestFiber[10] fibs;
foreach(ref fib; fibs)
fib = new TestFiber();

bool cont;
do {
cont = false;
foreach(fib; fibs) {
if (fib.state == Fiber.State.HOLD)
{
fib.call();
cont |= fib.state != Fiber.State.TERM;
}
}
} while (cont);

enum expSum = 1000 * 999 / 2;
foreach(fib; fibs)
{
assert(fib.sum == expSum);
}
}

unittest
{
runTen();
Thread[4] threads;
foreach(ref thr; threads)
{
thr = new Thread(&runTen);
thr.start();
}
}
}

version( OSX )
{
// NOTE: The Mach-O object file format does not allow for thread local
Expand Down

0 comments on commit f7e7eae

Please sign in to comment.