Created
June 19, 2023 08:26
-
-
Save FeepingCreature/c34ac021331697770c6c33e6e8d0332a to your computer and use it in GitHub Desktop.
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
module test; | |
import core.memory : GC; | |
import core.sync.semaphore; | |
import core.thread; | |
import std; | |
static string[] keys = [ | |
"foo", "bar", "baz", "whee", | |
"foo1", "foo2", "foo3", "foo4", "foo5", "foo6", "foo7", "foo8", | |
"bar1", "bar2", "bar3", "bar4", "bar5", "bar6", "bar7", "bar8", | |
"baz1", "baz2", "baz3", "baz4", "baz5", "baz6", "baz7", "baz8"]; | |
void spamalot(Semaphore sema, int i) { | |
auto rnd = Random(i); | |
int rand() => uniform(0, int.max, rnd); | |
void recursionTest(int depth) { | |
int r = rand(); | |
if (depth < 1000) { | |
recursionTest(depth + 1); | |
if (rand() % 300 == 0) | |
recursionTest(depth + 1); | |
} | |
string[string] assocArray; | |
static foreach (_; 20.iota) | |
{ | |
assocArray[keys[rand() % $].idup] = keys[rand() % $]; | |
} | |
} | |
// recursionTest(0); | |
sema.notify; | |
Thread.sleep(3600.seconds); | |
} | |
void main() { | |
Thread[] threads; | |
auto sema = new Semaphore(0); | |
enum threadCount = 100; | |
threadCount.iota.each!((i) { | |
auto thread = new Thread({ spamalot(sema, i); }); | |
thread.start; | |
threads ~= thread; | |
}); | |
// this clears the leak up. | |
// threads.each!((thread) { thread.join; }); | |
threadCount.iota.each!((i) { | |
sema.wait; | |
}); | |
writefln!"Done."; | |
GC.collect; | |
GC.minimize; | |
writefln!"Collected."; | |
// Now look at residential memory for the process. | |
Thread.sleep(3600.seconds); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment