# How to end simulation when there are forever-loops in sequence and monitor?

**URL:** <https://verificationacademy.com/forums/t/how-to-end-simulation-when-there-are-forever-loops-in-sequence-and-monitor/40172>\
**Category:** UVM\
**Tags:** systemverilog-uvm, UVM, forever\
**Created:** [March 19, 2022, 2:30am UTC](https://verificationacademy.com/forums/t/how-to-end-simulation-when-there-are-forever-loops-in-sequence-and-monitor/40172 "2022-03-19T02:30:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![UVM\_LOVE](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/uvm_love/32/1684_2.png) [@UVM\_LOVE](https://verificationacademy.com/forums/u/UVM_LOVE)\
**Post date:** [March 19, 2022, 2:30am UTC](https://verificationacademy.com/forums/t/how-to-end-simulation-when-there-are-forever-loops-in-sequence-and-monitor/40172/1 "2022-03-19T02:30:21Z")

</div>

Dear All,

I’m trying to understand uvm phase process. Especially, we can implement forever statment such as the below example.

> **[UVM Monitor \[uvm\_monitor\]](https://www.chipverify.com/uvm/uvm-monitor)**
>
> Learn all about UVM monitor (uvm\_monitor) class, how to create it, what to include in it, and how to setup an analysis port in it. Learn how to create the skele

```verilog
class my_monitor extends uvm_monitor;
 `uvm_component_utils (my_monitor)
...
 function new (string name, uvm_component parent)
 super.new (name, parent);
 endfunction

 virtual function void build_phase (uvm_phase phase)
 super.build_phase (phase);
 endfunction

 virtual task run_phase (uvm_phase phase);

 forever begin
 ...
 data_obj.data = vif.data;
 data_obj.addr = vif.addr;
...
 if (enable_coverage)
 data_obj.cg_trans.sample();
 // Send data object through the analysis
 mon_analysis_port.write (data_obj);
 end
 endtask
...
endclass

```

As you can see the above, there is implemented with foreever statement.  
I’m wonder that if we use forever statment, who/how does kill it?  
In [UVM Monitor - Verification Guide](https://verificationguide.com/uvm/uvm-monitor/) , some article answered by “don’t use forever statments”.  
Even if I implement a raise/drop objection in run\_phase, doesn’t forever stop?

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [March 19, 2022, 6:44am UTC](https://verificationacademy.com/forums/t/how-to-end-simulation-when-there-are-forever-loops-in-sequence-and-monitor/40172/2 "2022-03-19T06:44:24Z")

</div>

_In reply to [UVM\_LOVE](https://verificationacademy.com/forums/t/how-to-end-simulation-when-there-are-forever-loops-in-sequence-and-monitor/40172):_

The advice “don’t use forever statements” is incorrect. All run\_phase tasks in all components get killed when the last objection drops. You would not put a raise/drop objection around a forever loop like those used in a monitor or driver unless there was some condition to break out of the forever loop.

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [March 19, 2022, 2:42pm UTC](https://verificationacademy.com/forums/t/how-to-end-simulation-when-there-are-forever-loops-in-sequence-and-monitor/40172/3 "2022-03-19T14:42:29Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/how-to-end-simulation-when-there-are-forever-loops-in-sequence-and-monitor/40172/2):_

The statement “don’t use forever statements” is related to the body task of sequences. If your sequence runs forever your simulation will never stop.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [March 19, 2022, 4:39pm UTC](https://verificationacademy.com/forums/t/how-to-end-simulation-when-there-are-forever-loops-in-sequence-and-monitor/40172/4 "2022-03-19T16:39:02Z")

</div>

_In reply to [chr\_sue](https://verificationacademy.com/forums/t/how-to-end-simulation-when-there-are-forever-loops-in-sequence-and-monitor/40172/3):_

Incorrect. **All run\_phase tasks in all components get killed when the last objection drops.** A [slave/responder sequence](https://verificationacademy.com/cookbook/sequences/slave) is good counter argument.

---

<div class="post-metadata">

**Author:** ![kkpowar](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/k/9fc29f/32.png) [@kkpowar](https://verificationacademy.com/forums/u/kkpowar)\
**Post date:** [September 19, 2022, 3:49pm UTC](https://verificationacademy.com/forums/t/how-to-end-simulation-when-there-are-forever-loops-in-sequence-and-monitor/40172/5 "2022-09-19T15:49:49Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/how-to-end-simulation-when-there-are-forever-loops-in-sequence-and-monitor/40172/4):_

Hi in case of response handler Sequance (responder Sequance) which needs to have under forever loop. what do you suggest to achieve end of simulation independent of this Sequance completion.??
