Merge pull request #96 from vibe-d/fix_taskpool_shutdown
Fix TaskPool shutdown and hanging test case merged-on-behalf-of: Sönke Ludwig <s-ludwig@users.noreply.github.com>
This commit is contained in:
commit
38a1ef761c
|
@ -71,7 +71,6 @@ shared final class TaskPool {
|
||||||
m_state.lock.term = true;
|
m_state.lock.term = true;
|
||||||
m_signal.emit();
|
m_signal.emit();
|
||||||
|
|
||||||
auto ec = m_signal.emitCount;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
WorkerThread th;
|
WorkerThread th;
|
||||||
with (m_state.lock)
|
with (m_state.lock)
|
||||||
|
@ -81,6 +80,9 @@ shared final class TaskPool {
|
||||||
}
|
}
|
||||||
if (!th) break;
|
if (!th) break;
|
||||||
|
|
||||||
|
if (th is Thread.getThis())
|
||||||
|
continue;
|
||||||
|
|
||||||
() @trusted {
|
() @trusted {
|
||||||
try th.join();
|
try th.join();
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
@ -271,9 +273,8 @@ private final class WorkerThread : Thread {
|
||||||
|
|
||||||
logDebug("worker thread enter");
|
logDebug("worker thread enter");
|
||||||
TaskFuncInfo taskfunc;
|
TaskFuncInfo taskfunc;
|
||||||
while(true){
|
|
||||||
auto emit_count = m_pool.m_signal.emitCount;
|
auto emit_count = m_pool.m_signal.emitCount;
|
||||||
|
while(true) {
|
||||||
with (m_pool.m_state.lock) {
|
with (m_pool.m_state.lock) {
|
||||||
logDebug("worker thread check");
|
logDebug("worker thread check");
|
||||||
|
|
||||||
|
@ -282,7 +283,7 @@ private final class WorkerThread : Thread {
|
||||||
if (m_queue.consume(taskfunc)) {
|
if (m_queue.consume(taskfunc)) {
|
||||||
logDebug("worker thread got specific task");
|
logDebug("worker thread got specific task");
|
||||||
} else if (queue.consume(taskfunc)) {
|
} else if (queue.consume(taskfunc)) {
|
||||||
logDebug("worker thread got specific task");
|
logDebug("worker thread got unspecific task");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ void main()
|
||||||
|
|
||||||
void worker()
|
void worker()
|
||||||
{
|
{
|
||||||
ev.wait();
|
ev.wait(0);
|
||||||
ev.emit();
|
ev.emit();
|
||||||
setTimer(dur!"seconds"(1), {
|
setTimer(dur!"seconds"(1), {
|
||||||
auto c = atomicOp!"+="(counter, 1);
|
auto c = atomicOp!"+="(counter, 1);
|
||||||
|
|
Loading…
Reference in a new issue