Advertisement
Guest User

Untitled

a guest
Oct 26th, 2014
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env rdmd
  2.  
  3. import std.algorithm;
  4. import std.stdio;
  5. import std.conv;
  6.  
  7. import core.thread;
  8. import core.sync.mutex;
  9.  
  10. Mutex mutex;
  11.  
  12. void proc() {
  13.     foreach(int k; 1..6) {
  14.         synchronized(mutex) {
  15.             foreach(int m; 1..6) {
  16.                 writefln("Thread: %s, K.O. br: %d (%d/5)", Thread.getThis.name, k, m);
  17.                 Thread.sleep(dur!"seconds"(1));
  18.             }
  19.         }  
  20.     }
  21. }
  22.  
  23. void run() {
  24.     proc;
  25. }
  26.  
  27.  
  28. void main() {
  29.     mutex      = new Mutex;
  30.     auto group = new ThreadGroup;
  31.    
  32.     auto a = new Thread(&run);
  33.     a.name = "1";
  34.  
  35.     auto b = new Thread(&run);
  36.     b.name = "2";
  37.  
  38.     a.start();
  39.     b.start();
  40.  
  41.     group.add(a);
  42.     group.add(b);
  43.  
  44.     group.joinAll();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement