# Forever loop break

**URL:** <https://verificationacademy.com/forums/t/forever-loop-break/34175>\
**Category:** UVM\
**Tags:** UVM, Forever-Loop-Break-in-UVM\
**Created:** [March 9, 2018, 3:37pm UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175 "2018-03-09T15:37:12Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbasnet](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rbasnet](https://verificationacademy.com/forums/u/rbasnet)\
**Post date:** [March 9, 2018, 3:37pm UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/1 "2018-03-09T15:37:12Z")

</div>

How the forever loop breaks in the following code snippet? My assumption is the execution should remain inside forever loop indefinitely as there is no break condition. But the execution exits the loop to my surprise.

```verilog

task evsock_alarm_center::run_phase(uvm_phase phase);
     phase.raise_objection(this);	
	fork    
	  forever begin		     
	      int_fifo.get(gpio_item);	     
              parse_interrupt(gpio_item,interrupt_vector); //interrupt_vector_parsing
              irq_out=interrupt_vector[0]|| interrupt_vector[1]; //merge the irq_out 
        
              if(irq_out) begin       
                if(interrupt_vector[2]) begin
                  `uvm_info("!INTERRUPT TRIGGERED!", "Interrupt Source is EM Classifier", UVM_LOW)
                end
                if(interrupt_vector[3]) begin
                  `uvm_info("!INTERRUPT TRIGGERED!", "Interrupt Source is EM Queue Manager", UVM_LOW)
                end
                if(interrupt_vector[4]) begin 
                 `uvm_info("!INTERRUPT TRIGGERED!", "Interrupt Source is EM Scheduler", UVM_LOW)
                end
                if(interrupt_vector[5]) begin
                 `uvm_info("!INTERRUPT TRIGGERED!", "Interrupt Source is BM", UVM_LOW)
                end              
	  end
	join_none
    phase.drop_objection(this);
	
endtask

```

---

<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 9, 2018, 3:44pm UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/2 "2018-03-09T15:44:19Z")

</div>

_In reply to [rbasnet](https://verificationacademy.com/forums/t/forever-loop-break/34175):_

It does never break and the objection will never drop, i.e. your simulation is running forever.

---

<div class="post-metadata">

**Author:** ![cuonghle](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/cuonghle/32/3231_2.png) [@cuonghle](https://verificationacademy.com/forums/u/cuonghle)\
**Post date:** [March 9, 2018, 3:56pm UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/3 "2018-03-09T15:56:40Z")

</div>

_In reply to [chr\_sue](https://verificationacademy.com/forums/t/forever-loop-break/34175/2):_

> _In reply to [rbasnet](https://verificationacademy.com/forums/t/forever-loop-break/34175/2):_  
> It does never break and the objection will never drop, i.e. your simulation is running forever.

could you explain why the objection will never drop? I think in run phase, he uses the fork/join\_none then the phase.drop\_objection will be executed in main thread right?  
I believe, the objection will raise and drop immediatly after fork. The fork will be terminated when all other phases parallel running with run phase are finished.

Correct me if Im wrong.

---

<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 9, 2018, 4:04pm UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/4 "2018-03-09T16:04:56Z")

</div>

_In reply to [cuonghl](https://verificationacademy.com/forums/t/forever-loop-break/34175/3):_

Oh sorry, I have to correct myself. It is a fork/join\_none. The objection is dropping immediately after the join\_none and leaving the run\_phase task.

---

<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 9, 2018, 4:22pm UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/5 "2018-03-09T16:22:01Z")

</div>

_In reply to [rbasnet](https://verificationacademy.com/forums/t/forever-loop-break/34175/4):_

You are spawning the forever loop in a fork/join\_none process, so the that runs in the background while you immediately drop the objection. Why are you raising/dropping an objection?

---

<div class="post-metadata">

**Author:** ![VE1](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/54ee81/32.png) [@VE1](https://verificationacademy.com/forums/u/VE1)\
**Post date:** [March 11, 2018, 7:55pm UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/6 "2018-03-11T19:55:40Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/forever-loop-break/34175/5):_

A following-up question. Let us assume Rbasent’s code is correct. When the fork/join\_none kick off ? According the LRM, fork/join\_none is started at the first blocking statement in main thread after join\_none.

---

<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 12, 2018, 7:00am UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/7 "2018-03-12T07:00:34Z")

</div>

_In reply to [VE](https://verificationacademy.com/forums/t/forever-loop-break/34175/6):_

As the LRMs says, the parent thread has to block or terminate before the fork/join\_none process starts executing the forked process. Since each component’s run\_phase is started as a separate thread, this fork/join\_none gets scheduled upon returning from the task vsock\_alarm\_center::run\_phase. But there may be other component run\_phases ahead in the queue to execute before getting to the fork thread.

---

<div class="post-metadata">

**Author:** ![rbasnet](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rbasnet](https://verificationacademy.com/forums/u/rbasnet)\
**Post date:** [March 12, 2018, 11:32am UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/8 "2018-03-12T11:32:34Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/forever-loop-break/34175/7):_

> _In reply to [rbasnet](https://verificationacademy.com/forums/t/forever-loop-break/34175/7):_  
> You are spawning the forever loop in a fork/join\_none process, so the that runs in the background while you immediately drop the objection. Why are you raising/dropping an objection?

The objection raising/dropping is redundant. That was my bad. Now I got rid of the objection but still the execution comes out of the forever loop. I tried with the fork\_join and fork\_join\_any to see if that makes any difference but no. I also completely got rid of the fork and tried with the forever loop only and i could see that the execution still exits the forever loop. What is going on here? Seems like I am missing something here.

---

<div class="post-metadata">

**Author:** ![rbasnet](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rbasnet](https://verificationacademy.com/forums/u/rbasnet)\
**Post date:** [March 12, 2018, 1:58pm UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/9 "2018-03-12T13:58:37Z")

</div>

_In reply to [rbasnet](https://verificationacademy.com/forums/t/forever-loop-break/34175/8):_

> _In reply to [dave\_59](https://verificationacademy.com/forums/t/forever-loop-break/34175/8):_  
> The objection raising/dropping is redundant. That was my bad. Now I got rid of the objection but still the execution comes out of the forever loop. I tried with the fork\_join and fork\_join\_any to see if that makes any difference but no. I also completely got rid of the fork and tried with the forever loop only and i could see that the execution still exits the forever loop. What is going on here? Seems like I am missing something here.

From the simulation it seems that the loop executes as many times as I have items in the fifo. If there are no items in the fifo, regardless of the call to get method, the loop exits. My understanding is the execution should stuck in the call to get method as it is a blocking call even if there are no items in the fifo. What is that I am missing here?

---

<div class="post-metadata">

**Author:** ![cuonghle](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/cuonghle/32/3231_2.png) [@cuonghle](https://verificationacademy.com/forums/u/cuonghle)\
**Post date:** [March 12, 2018, 3:31pm UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/10 "2018-03-12T15:31:57Z")

</div>

_In reply to [rbasnet](https://verificationacademy.com/forums/t/forever-loop-break/34175/9):_

The your loop is located in run\_phase, when the run\_phase complete, simulation will terminate your fork/join\_none and the loop as well. I think, the loop exists because your run\_phase is completed (when all other phases such as reset, configure, main, shutdown, etc… parallel running with run\_phase are finished). Please check again.

---

<div class="post-metadata">

**Author:** ![VE1](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/54ee81/32.png) [@VE1](https://verificationacademy.com/forums/u/VE1)\
**Post date:** [March 12, 2018, 8:54pm UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/11 "2018-03-12T20:54:54Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/forever-loop-break/34175/10):_

> _In reply to [VE](https://verificationacademy.com/forums/t/forever-loop-break/34175/10):_  
> As the LRMs says, the parent thread has to block or terminate before the fork/join\_none process. Since each component’s run\_phase is started as a separate thread, this fork/join\_none gets scheduled upon returning from the task vsock\_alarm\_center::run\_phase. But there may be other component run\_phases ahead in the queue to execute before getting to the fork thread.

Thanks Dave. Would you elaborate " As the LRMs says, the parent thread has to block or terminate before the fork/join\_none process."? On IEEE1800-2012, P175. it says :  
join\_none :: The parent process continues to execute concurrently with all the processes spawned by the fork. The spawned processes do not start executing until the parent thread executes a blocking statement or terminates.

Just want to make sure i understand it correctly.  
Thanks

---

<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 12, 2018, 9:46pm UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/12 "2018-03-12T21:46:22Z")

</div>

_In reply to [VE](https://verificationacademy.com/forums/t/forever-loop-break/34175/11):_

Help me with what you are having trouble understanding. Do you know

- “process” and “thread” are interchangeable words
- what a parent thread is?
- what a spawned or forked thread is? ( a child of the parent thread )
- what it means to encounter a blocking statement?
- the conditions that terminate a process?

---

<div class="post-metadata">

**Author:** ![rbasnet](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rbasnet](https://verificationacademy.com/forums/u/rbasnet)\
**Post date:** [March 13, 2018, 7:50am UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/13 "2018-03-13T07:50:53Z")

</div>

_In reply to [cuonghl](https://verificationacademy.com/forums/t/forever-loop-break/34175/12):_

Hi Cuonghl

Are you trying to say that regardless of the implementation in the run phase, the run phase should terminate at some point of time during the simulation and the execution proceeds to extract phase? Please consider the code below. What makes the forever loop break? My understanding is, the execution should get stuck forever inside the loop as get method is blocking. It should not return unless the item is available in the fifo and hence the execution should get stuck forever. If i remove the int\_fifo.get(), then the execution remains inside the forever loop indefinitely. Any pointers will be appreciated!!!

```auto
uvm_tlm_analysis_fifo #(gpio_sequence_item) int_fifo;
...
task evsock_alarm_center::run_phase(uvm_phase phase);	   
   forever begin		     
     int_fifo.get(gpio_item);	              
   end
endtask

```

---

<div class="post-metadata">

**Author:** ![cuonghle](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/cuonghle/32/3231_2.png) [@cuonghle](https://verificationacademy.com/forums/u/cuonghle)\
**Post date:** [March 13, 2018, 9:03am UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/14 "2018-03-13T09:03:00Z")

</div>

_In reply to [rbasnet](https://verificationacademy.com/forums/t/forever-loop-break/34175/13):_

The run\_phase will be terminated by following reasons:

- The post\_shutdown\_phase is finished (all objection are dropped)
- Timeout 9200s.

In your example, the forever loop in run\_phase will be terminated if all objections (from pre\_reset to post\_shutdown phase) are dropped. Let’s see the following example:

```verilog

  class phase_test extends uvm_test;
    `uvm_component_utils(phase_test)
    function new(string name, uvm_component parent);
      super.new(name, parent);
    endfunction : new
    
    task main_phase(uvm_phase phase);
      phase.raise_objection(this);
      #5;
      phase.drop_objection(this);
    endtask
    
    task run_phase(uvm_phase phase);
      forever begin
        #1;
        `uvm_info("PHASE_TEST", "Printed forever loop", UVM_NONE)
      end
    endtask
  endclass 

```

Can you guess, how many line “Printed forever loop” will be displayed in forever loop of run\_phase? It will never stuck forever because in main\_phase, the objection is dropped after 5ns delay.

---

<div class="post-metadata">

**Author:** ![rbasnet](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rbasnet](https://verificationacademy.com/forums/u/rbasnet)\
**Post date:** [March 13, 2018, 9:34am UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/15 "2018-03-13T09:34:02Z")

</div>

_In reply to [cuonghl](https://verificationacademy.com/forums/t/forever-loop-break/34175/14):_  
Now I see that the simulation time advances when executing the instructions inside the forever loop and ultimately the run phase proceeds to the extract phase. Had there been no instructions to execute inside the forever loop (I tried this to check), the simulation time never advances and the forever loop is never exited. Thanks for the replies…:)

---

<div class="post-metadata">

**Author:** ![cuonghle](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/cuonghle/32/3231_2.png) [@cuonghle](https://verificationacademy.com/forums/u/cuonghle)\
**Post date:** [March 13, 2018, 9:56am UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/16 "2018-03-13T09:56:30Z")

</div>

_In reply to [rbasnet](https://verificationacademy.com/forums/t/forever-loop-break/34175/15):_

You can’t execute a task with zero timing in forever loop of run\_phase, it will stuck forever.

---

<div class="post-metadata">

**Author:** ![vk7715](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/8edcca/32.png) [@vk7715](https://verificationacademy.com/forums/u/vk7715)\
**Post date:** [April 21, 2023, 5:43am UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/17 "2023-04-21T05:43:29Z")

</div>

_In reply to [cuonghle](https://verificationacademy.com/forums/t/forever-loop-break/34175/16):_

Hi Cuonghle, could you please explain why a task with zero timing in forever loop of run\_phase will be stuck forever? I get that a forever loop goes forever but what different does a task with zero timing make? Also, isn’t that technically a function?

---

<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:** [April 21, 2023, 10:35am UTC](https://verificationacademy.com/forums/t/forever-loop-break/34175/18 "2023-04-21T10:35:10Z")

</div>

_In reply to [vk7715](https://verificationacademy.com/forums/t/forever-loop-break/34175/17):_

A forever loop in the run\_phase will run forever if there is no break statement. It will not stuck, but override any previous values.
