Created
June 13, 2023 17:37
-
-
Save run-dlang/88cefdde8bb7f61f173ad11b2a03d5ee to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
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
import core.thread; | |
import std; | |
import std.parallelism; | |
shared string[string] aa; | |
void fun() { | |
foreach (i; 0 .. 5) { | |
writeln("fun", i, aa); | |
foreach (num; parallel(iota(5))) { | |
// writeln(num); | |
} | |
Thread.sleep(5.seconds); | |
} | |
} | |
void main() { | |
writeln("start", aa); | |
auto aaTemp = [ "abc" : "123" ]; | |
aa = cast(shared)aaTemp; | |
writeln(aa); | |
foreach (num; parallel(iota(5))) { | |
auto t = new Thread({fun();}).start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment