Guest User

Untitled

a guest
Jan 15th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. module top();
  2.  
  3. class c;
  4.  
  5. string name;
  6. int count;
  7.  
  8. function new(string _name, int _count);
  9. name = _name;
  10. count = _count;
  11. endfunction
  12.  
  13. task t1();
  14. timer();
  15. $display("%t %s timer completed", $time, name);
  16. endtask
  17.  
  18. task run();
  19. fork
  20. t1();
  21. disabler();
  22. join
  23. endtask
  24.  
  25. task timer();
  26. $display("%t %s starting timer with count=%0d", $time, name, count);
  27. repeat(count) #1;
  28. endtask
  29.  
  30. task disabler();
  31. repeat(count/2) #1;
  32. disable timer;
  33. endtask
  34.  
  35. endclass
  36.  
  37. class ex;
  38.  
  39. c c1;
  40. c c2;
  41.  
  42. function new();
  43. c1 = new("c1", 10);
  44. c2 = new("c2", 20);
  45. endfunction
  46.  
  47. task run();
  48. fork
  49. c1.run();
  50. c2.run();
  51. join_none
  52. endtask
  53.  
  54. endclass
  55.  
  56. ex e = new;
  57.  
  58. initial begin
  59. e.run();
  60. end
  61.  
  62. endmodule
  63.  
  64. 0 c1 starting timer with count=10
  65. 0 c2 starting timer with count=20
  66. 5 c2 timer completed
  67. 5 c1 timer completed
  68.  
  69. class c;
  70. process p1;
  71.  
  72. task run();
  73. fork
  74. begin
  75. p1 = process::self(); //Get process of this begin..end block
  76. $display("%t %s starting timer with count=%0d", $time, name, count);
  77. repeat(count) #1;
  78. end
  79. disabler()
  80. join_none
  81. endtask
  82.  
  83. task disabler();
  84. wait (p1 != null);
  85. repeat(count/2) #1;
  86. p1.kill();
  87. endtask
Add Comment
Please, Sign In to add comment