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

Commit

Permalink
Merge pull request #1252 from Dzugaru/patch-1
Browse files Browse the repository at this point in the history
Allow a fiber in HOLD state to be reset bypassing scope(exit) etc.
  • Loading branch information
MartinNowak committed May 7, 2015
2 parents 7493a59 + ecada64 commit 2c74db0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/core/thread.d
Expand Up @@ -4013,23 +4013,23 @@ class Fiber

/**
* Resets this fiber so that it may be re-used, optionally with a
* new function/delegate. This routine may only be called for
* new function/delegate. This routine should only be called for
* fibers that have terminated, as doing otherwise could result in
* scope-dependent functionality that is not executed.
* Stack-based classes, for example, may not be cleaned up
* properly if a fiber is reset before it has terminated.
* properly if a fiber is reset before it has terminated.
*
* In:
* This fiber must be in state TERM.
* This fiber must be in state TERM or HOLD.
*/
final void reset() nothrow
in
{
assert( m_state == State.TERM || m_state == State.HOLD );
assert( m_ctxt.tstack == m_ctxt.bstack );
}
body
{
m_ctxt.tstack = m_ctxt.bstack;
m_state = State.HOLD;
initStack();
m_unhandled = null;
Expand Down Expand Up @@ -5036,6 +5036,17 @@ unittest
expect(fib, "delegate");
}

// Test unsafe reset in hold state
unittest
{
auto fib = new Fiber(function {ubyte[2048] buf = void; Fiber.yield();}, 4096);
foreach (_; 0 .. 10)
{
fib.call();
assert(fib.state == Fiber.State.HOLD);
fib.reset();
}
}

// stress testing GC stack scanning
unittest
Expand Down

0 comments on commit 2c74db0

Please sign in to comment.