Created
September 30, 2023 09:20
-
-
Save run-dlang/1c33e9804ea1f4368f264e985e364004 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
This file contains hidden or 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 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