Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- import std.random;
- import std.concurrency;
- import core.sys.posix.stdlib : exit;
- void search(uint min, uint max, uint searchFor, Tid thisId){
- writeln("test1");
- uint guess = uint.init;
- receive((bool finish) {
- if(finish == true){
- return;
- }
- });
- while(guess != searchFor){
- writeln("test2");
- guess = uniform(min, max);
- if(guess == searchFor){
- writeln(thisId, " Found the Number. ", guess);
- foreach(Tid thr; pool){
- send(thr, true);
- send(ownerTid, "Yeah");
- }
- return;
- }
- }
- }
- __gshared Tid[] pool;
- __gshared bool finish = false;
- void main(){
- for(uint x = 1; x <= 3; x += 1){
- Tid tid = spawn(&search, 1u, 200u, 17u, thisTid);
- pool ~= tid;
- }
- while(true){
- receive((string msg){
- writeln("all done !");
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment