Created
February 5, 2022 17:34
-
-
Save DeivAstra/5a5a7b24b8179890efa36657ed8095ad to your computer and use it in GitHub Desktop.
Error creating many threads (D language)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Error output: | |
// ... | |
// desctructed: 32631 | |
// desctructed: 32632 | |
// core.thread.threadbase.ThreadError@src/core/thread/threadbase.d(1217): Error creating thread | |
module test.thread; | |
import std.stdio; | |
import core.thread.osthread; | |
import core.time; | |
void main() { | |
massThreadTest(); | |
} | |
private shared Duration dur1ms = dur!("msecs")(1); | |
private class LogThread : Thread { | |
private static shared int desctructed; | |
this(void function() fn, size_t sz = 0) { | |
super(fn, sz); | |
} | |
this( void delegate() dg, size_t sz = 0 ){ | |
super(dg, sz); | |
} | |
~this() { | |
desctructed = desctructed + 1; | |
writeln("desctructed: ", desctructed); | |
} | |
} | |
private void massThreadTest() { | |
writeln("Start"); | |
const int count = 1_000_000; | |
foreach(int i; 1..count) { | |
new LogThread(&run).start(); | |
//write(i);write(' '); | |
Thread.sleep(dur1ms); | |
} | |
writeln("End"); | |
} | |
private void run() {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment