Merge pull request #236 from vibe-d/fix_task_interrupt_assertion_failure

Avoid bogus "A task cannot interrupt itself" assertion failure.
This commit is contained in:
Leonid Kramer 2020-11-20 09:53:17 +01:00 committed by GitHub
commit 983cc15f70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -97,7 +97,14 @@ struct Task {
void join() @trusted { if (m_fiber) m_fiber.join!true(m_taskCounter); } void join() @trusted { if (m_fiber) m_fiber.join!true(m_taskCounter); }
void joinUninterruptible() @trusted nothrow { if (m_fiber) m_fiber.join!false(m_taskCounter); } void joinUninterruptible() @trusted nothrow { if (m_fiber) m_fiber.join!false(m_taskCounter); }
void interrupt() @trusted nothrow { if (m_fiber) m_fiber.interrupt(m_taskCounter); } void interrupt() @trusted nothrow { if (m_fiber && this.running) m_fiber.interrupt(m_taskCounter); }
unittest { // regression test for bogus "task cannot interrupt itself"
import vibe.core.core : runTask;
auto t = runTask({});
t.join();
runTask({ t.interrupt(); }).join();
}
string toString() const @safe { import std.string; return format("%s:%s", () @trusted { return cast(void*)m_fiber; } (), m_taskCounter); } string toString() const @safe { import std.string; return format("%s:%s", () @trusted { return cast(void*)m_fiber; } (), m_taskCounter); }
@ -138,7 +145,6 @@ struct Task {
} }
} }
/** Settings to control the behavior of newly started tasks. /** Settings to control the behavior of newly started tasks.
*/ */
struct TaskSettings { struct TaskSettings {