# Question on fork

**URL:** <https://verificationacademy.com/forums/t/question-on-fork/42060>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, thread-fork\
**Created:** [August 3, 2023, 7:33am UTC](https://verificationacademy.com/forums/t/question-on-fork/42060 "2023-08-03T07:33:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marathuteja](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/dec6dc/32.png) [@marathuteja](https://verificationacademy.com/forums/u/marathuteja)\
**Post date:** [August 3, 2023, 7:33am UTC](https://verificationacademy.com/forums/t/question-on-fork/42060/1 "2023-08-03T07:33:43Z")

</div>

Write a timeout detection check to flag an error if “status ok” is not asserted with in 1microsecond of asserting “start”. using fork not with assertion can any one help me how to write a fork block for this check.

---

<div class="post-metadata">

**Author:** ![KillSteal](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/k/74df32/32.png) [@KillSteal](https://verificationacademy.com/forums/u/KillSteal)\
**Post date:** [August 3, 2023, 2:35pm UTC](https://verificationacademy.com/forums/t/question-on-fork/42060/2 "2023-08-03T14:35:55Z")

</div>

_In reply to [marathuteja](https://verificationacademy.com/forums/t/question-on-fork/42060):_

Something like this maybe ?

```verilog
module test();
  int start = 1;
  int status;
  bit timeout_flag = 0;
  
  initial begin
    
    wait(start==1) ;
    fork begin //isolator
      fork 
        begin
          wait(status == 1) ; //wait for status ok
        end
        begin
          #1us;
          timeout_flag = 1;
        end
      join_any;
      if(timeout_flag == 1) 
        $display("Fail");
      disable fork;  
    end join //isolator
    
  end
  
endmodule

```

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [August 3, 2023, 6:30pm UTC](https://verificationacademy.com/forums/t/question-on-fork/42060/3 "2023-08-03T18:30:06Z")

</div>

_In reply to [KillSteal](https://verificationacademy.com/forums/t/question-on-fork/42060/2):_

KillSteal has a good start, but I prefer the approach I used in my paper  
\*\*Understanding the SVA Engine Using the Fork-Join Model  
\*\* [Verification Horizons](https://verificationacademy.com/verification-horizons/july-2020-volume-16-issue-2)  
Using a model, the paper addresses important concepts about attempts and threads. Emphasizes the total independence of attempts.

Note that for every posedge of _start_ I trigger the automatic task check\_ok.  
This is just like a concurrent assertion where at every clocking event you trigger the property.

[Edit code - EDA Playground](https://www.edaplayground.com/x/aHsU) // code  
[EPWave Waveform Viewer](https://www.edaplayground.com/w/x/Ssw) // wave  
I modified the units of time for demo use.

```verilog

// Write a timeout detection check to flag an error if "status ok" is not asserted 
// within 1microsecond of asserting "start". using fork not with assertion can any 
// one help me how to write a fork block for this check.

module test();
    typedef enum {IDLE, OK} status_e; // 
     //status_e status; 
     int status=0;
     bit start, started; 
     int pass, fail; 

  always @(posedge start) 
      fork check_ok(); // trigger the task 
      join_none

    task automatic check_ok();
      bit timeout_flag=0; 
      started=1; // debug
      fork begin 
        fork 
          begin
            // if(status == 0) @(posedge status) pass=1; //wait for status ok
            wait(status==1); // above works too
          end
          begin
            #15;
            timeout_flag = 1;
          end
        join_any;
        am_stat_ok: assert(timeout_flag == 0) pass=pass+1; 
        else begin fail=fail+1; $display("Fail"); end
        //disable fork;  
      end join //isolator
    endtask

    initial begin
        $dumpfile("dump.vcd"); $dumpvars;
        status=0; //IDLE;
        #10 start=1; 
        #3 status=1;
        #30 status=0;
        #3 $finish;    
    end
  endmodule
  

```

Ben Cohen  
[Ben@systemverilog.us](mailto:Ben@systemverilog.us)  
Link to the list of papers and books that I wrote, many are now donated.

> **[Cohen\_Links\_to\_papers\_books.pdf](https://systemverilog.us/vf/Cohen_Links_to_papers_books.pdf)**
>
> 141.16 KB

or [Cohen\_Links\_to\_papers\_books - Google Docs](https://rb.gy/ibks5p)

Getting started with verification with SystemVerilog

> **[Ben Cohen on LinkedIn: Road map to start with verification: SV, SVA , UVM and TB](https://www.linkedin.com/posts/ben-cohen-1172a0_road-map-to-start-with-verification-sv-activity-7050267628208062464-wnzN?utm_source=share&utm_medium=member_desktop)**
>
> Got this question: 
> Q: I need your advice in getting started with verification with systemverilog. I 've built various projects using Verilog and they was…
