Advertisement
Guest User

Untitled

a guest
Nov 19th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.61 KB | None | 0 0
  1. import core.thread;
  2. import std.stdio;
  3. import std.conv;
  4.  
  5. shared string[] output;
  6. shared int threadCount = 0;
  7. shared int counter = 0;
  8.  
  9. void run()
  10. {
  11.     threadCount++;
  12.     for(int i = 0; i < 10; i++)
  13.     {
  14.         string test = "T"~to!string(threadCount)~": "~to!string(counter++);
  15.         output ~= test;
  16.     }
  17. }
  18.  
  19. int main()
  20. {
  21.     Thread testThread1 = new Thread(&run);
  22.     Thread testThread2 = new Thread(&run);
  23.     testThread1.start();
  24.     testThread2.start();
  25.     testThread1.join();
  26.     testThread2.join();
  27.     for(int i = 0; i < output.length; i++)
  28.          writeln(output[i]);
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement