Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created June 13, 2023 17:37
Show Gist options
  • Save run-dlang/88cefdde8bb7f61f173ad11b2a03d5ee to your computer and use it in GitHub Desktop.
Save run-dlang/88cefdde8bb7f61f173ad11b2a03d5ee to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
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