Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module top();
- class c;
- string name;
- int count;
- function new(string _name, int _count);
- name = _name;
- count = _count;
- endfunction
- task t1();
- timer();
- $display("%t %s timer completed", $time, name);
- endtask
- task run();
- fork
- t1();
- disabler();
- join
- endtask
- task timer();
- $display("%t %s starting timer with count=%0d", $time, name, count);
- repeat(count) #1;
- endtask
- task disabler();
- repeat(count/2) #1;
- disable timer;
- endtask
- endclass
- class ex;
- c c1;
- c c2;
- function new();
- c1 = new("c1", 10);
- c2 = new("c2", 20);
- endfunction
- task run();
- fork
- c1.run();
- c2.run();
- join_none
- endtask
- endclass
- ex e = new;
- initial begin
- e.run();
- end
- endmodule
- 0 c1 starting timer with count=10
- 0 c2 starting timer with count=20
- 5 c2 timer completed
- 5 c1 timer completed
- class c;
- process p1;
- task run();
- fork
- begin
- p1 = process::self(); //Get process of this begin..end block
- $display("%t %s starting timer with count=%0d", $time, name, count);
- repeat(count) #1;
- end
- disabler()
- join_none
- endtask
- task disabler();
- wait (p1 != null);
- repeat(count/2) #1;
- p1.kill();
- endtask
Add Comment
Please, Sign In to add comment