Allow a fiber in HOLD state to be reset bypassing scope(exit) etc. #1252
Conversation
* so it may leak resources which will lead to stack overflow if reset | ||
* is called too many times for such a fiber. It will | ||
* properly reset the stack though, so the fiber should behave like | ||
* a new one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's actually much more confusing than before.
One should only reset a fiber in term state, because resetting it in hold state won't cleanup the stack, e.g. scope(exit) and struct destructors aren't called.
Looking at the implementation again, there is indeed a bug. |
Now I get it, reset without parameters works for HOLD state iff the stack is clean. Reset with parameters (new function/delegate) works with any state cause there is no check there and leads to stack overflow.
That would be awesome, one could cope with scope(exit) and struct destructors not executing but having a way to completely reset HOLD fiber is very nice. |
Can you change the pull to just do that and add a test case. unittest
{
// test unsafe reset in hold state
auto fib = new Fiber({ubyte[2048] buf = void; Fiber.yield();}, 4096);
foreach (_; 0 .. 10)
{
fib.call();
assert(fib.state == Fiber.State.HOLD);
fib.reset();
}
} |
Did that, rebuilt everything with Digger on win32 and that test case works. |
Auto-merge toggled on |
Thx |
Allow a fiber in HOLD state to be reset bypassing scope(exit) etc.
Discussion: http://forum.dlang.org/thread/bltdzwskligncpgwdmxc@forum.dlang.org