Guest User

Untitled

a guest
May 28th, 2018
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.96 KB | None | 0 0
  1. import std.stdio;
  2. import std.random;
  3. import std.concurrency;
  4. import core.sys.posix.stdlib : exit;
  5.  
  6. void search(uint min, uint max, uint searchFor, Tid thisId){
  7.     writeln("test1");
  8.  
  9.     uint guess = uint.init;
  10.     receive((bool finish) {
  11.         if(finish == true){
  12.             return;
  13.         }
  14.     });
  15.     while(guess != searchFor){
  16.         writeln("test2");
  17.  
  18.         guess = uniform(min, max);
  19.         if(guess == searchFor){
  20.             writeln(thisId, " Found the Number. ", guess);
  21.             foreach(Tid thr; pool){
  22.                 send(thr, true);
  23.                 send(ownerTid, "Yeah");
  24.             }
  25.             return;
  26.         }
  27.     }
  28. }
  29.  
  30. __gshared Tid[] pool;
  31. __gshared bool finish = false;
  32.  
  33. void main(){
  34.     for(uint x = 1; x <= 3; x += 1){
  35.         Tid tid = spawn(&search, 1u, 200u, 17u, thisTid);
  36.         pool ~= tid;
  37.     }
  38.  
  39.     while(true){
  40.       receive((string msg){
  41.         writeln("all done !");
  42.       });
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment