Skip to content

TaskPool blocked when execute another task with TaskPool #10477

Open
@dlangBugzillaToGithub

Description

@dlangBugzillaToGithub

bitworld reported this on 2021-09-30T03:29:42Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=22346

Description

OS: Debian 4.9.144-3.1 (2019-02-19) x86_64 GNU/Linux
Compiler: DMD64 D Compiler v2.097.2

Here is the test code:

```d
import std.stdio;

import core.thread;
import core.time;

import std.parallelism;
import std.experimental.logger;

void main() {
	testTaskPool();
}

void testTaskPool() {

    // enum Total = 15;  // It's Ok when Total <= 15
    enum Total = 16;  // It's blocked by Thread.sleep(dur) when Total >= 16;

    for(size_t group = 0; group<Total; group++) {
		
		auto testTask = task(() {
				tracef("testing...");
				
				try {
					useTaskPool(); 	// bug test
					// useThread(); 		// It's always ok
				} catch(Exception ex) {
					warning(ex);
				}

				Duration dur = 10.seconds;
				infof("Sleeping %s", dur);
				Thread.sleep(dur);
				infof("awake now");
				tracef("testing done");
		});

		taskPool.put(testTask);
    }

    warning("press any key to close");
    getchar();	
}


void useThread() {
	Thread th = new Thread(&doSomething);
	th.start();
	// th.join();
}

void useTaskPool() {
	auto testTask = task(&doSomething);
	taskPool.put(testTask);
}

```

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions