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

Commit

Permalink
More unittests to test stack scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNowak committed Sep 27, 2013
1 parent acbf662 commit 9cf15b6
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/core/thread.d
Expand Up @@ -4415,6 +4415,86 @@ unittest
expect(fib, "delegate");
}


// stress testing GC stack scanning
unittest
{
import core.memory;

static void unreferencedThreadObject()
{
static void sleep() { Thread.sleep(dur!"msecs"(100)); }
auto thread = new Thread(&sleep);
thread.start();
}
unreferencedThreadObject();
GC.collect();

static class Foo
{
this(int value)
{
_value = value;
}

int bar()
{
return _value;
}

int _value;
}

static void collect()
{
auto foo = new Foo(2);
assert(foo.bar() == 2);
GC.collect();
Fiber.yield();
GC.collect();
assert(foo.bar() == 2);
}

auto fiber = new Fiber(&collect);

fiber.call();
GC.collect();
fiber.call();

// thread reference
auto foo = new Foo(2);

void collect2()
{
assert(foo.bar() == 2);
GC.collect();
Fiber.yield();
GC.collect();
assert(foo.bar() == 2);
}

fiber = new Fiber(&collect2);

fiber.call();
GC.collect();
fiber.call();

static void recurse(size_t cnt)
{
--cnt;
Fiber.yield();
if (cnt)
{
auto fib = new Fiber(() { recurse(cnt); });
fib.call();
GC.collect();
fib.call();
}
}
fiber = new Fiber(() { recurse(20); });
fiber.call();
}

}

version( AsmX86_64_Posix )
Expand Down

0 comments on commit 9cf15b6

Please sign in to comment.