Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - #!/usr/bin/env rdmd
 - import std.algorithm;
 - import std.stdio;
 - import std.conv;
 - import core.thread;
 - import core.sync.mutex;
 - Mutex mutex;
 - void proc() {
 - foreach(int k; 1..6) {
 - synchronized(mutex) {
 - foreach(int m; 1..6) {
 - writefln("Thread: %s, K.O. br: %d (%d/5)", Thread.getThis.name, k, m);
 - Thread.sleep(dur!"seconds"(1));
 - }
 - }
 - }
 - }
 - void run() {
 - proc;
 - }
 - void main() {
 - mutex = new Mutex;
 - auto group = new ThreadGroup;
 - auto a = new Thread(&run);
 - a.name = "1";
 - auto b = new Thread(&run);
 - b.name = "2";
 - a.start();
 - b.start();
 - group.add(a);
 - group.add(b);
 - group.joinAll();
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment