Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created September 30, 2023 09:20
Show Gist options
  • Save run-dlang/1c33e9804ea1f4368f264e985e364004 to your computer and use it in GitHub Desktop.
Save run-dlang/1c33e9804ea1f4368f264e985e364004 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
import std.stdio;
import core.thread;
struct Player {
int number;
void parallel_op() {
writefln("match %s has begun", number);
// Wait for a while to simulate a long-lasting operation
Thread.sleep(2.seconds);
writefln("match %s has ended", number);
}
}
void main() {
auto players =
[ Player(1), Player(2), Player(3),Player(4) ];
foreach (player; players) {
player.parallel_op();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment