Advertisement
Guest User

Untitled

a guest
Oct 26th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.70 KB | None | 0 0
  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. __gshared Mutex mutex;
  11.  
  12. static this() {
  13.     mutex = new Mutex;
  14. }
  15.  
  16. void proc() {
  17.     foreach(int k; 1..6) {
  18.         synchronized(mutex) {
  19.             foreach(int m; 1..6) {
  20.                 writefln("Thread: %s, K.O. br: %d (%d/5)", Thread.getThis.name, k, m);
  21.                 Thread.sleep(dur!"msecs"(50));
  22.             }
  23.         }  
  24.         Thread.sleep(dur!"msecs"(50));
  25.     }
  26. }
  27.  
  28. void run() {
  29.     proc;
  30. }
  31.  
  32.  
  33. void main() {
  34.     auto group = new ThreadGroup;
  35.    
  36.     auto a = new Thread(&run);
  37.     a.name = "1";
  38.  
  39.     auto b = new Thread(&run);
  40.     b.name = "2";
  41.  
  42.     a.start();
  43.     b.start();
  44.  
  45.     group.add(a);
  46.     group.add(b);
  47.  
  48.     group.joinAll();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement