Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:13:27+00:00 2026-06-12T08:13:27+00:00

In SystemVerilog, one can use the disable construct to terminate named blocks or tasks.

  • 0

In SystemVerilog, one can use the disable construct to terminate named blocks or tasks. But I found today that disabling a task within a class instance affects all copies of the task in all class instances.

Consider a class which has a few tasks defined within it. If, internal to the class, there is a call to disable <taskname>, this will disable all copies of the task across all instances of the class. This is not the behavior I expected, but it is correct according to the LRM:

If a task is enabled more than once, then disabling such a task shall disable all activations of the task.

Is there a mechanism or workaround to disable only the task within a specific instance of a class?

The code below highlights the problem I am facing. Basically, I have a timer task which I want to disable due to some other event. This is all contained within a class. In my verification environment I have multiple instances of this class and they operate entirely independently. So disabling the timer within one instance should not affect the others. But the way disable works it is affecting the other instances.

I tried disable this.timer but that did not compile.

In this example, I have two instances of class c which contains a timer task. There is a disabler task which is started in parallel which makes the call to disable timer. The intent in this example is for timer to get disabled half-way through its count. So c1 would get disabled at time 5, and c2 would get disabled at time 10. However, they both are disabled at time 5, because the disable timer call originating in c1 disables the task in both c1 and c2.

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

Output:

               0 c1 starting timer with count=10
               0 c2 starting timer with count=20
               5 c2 timer completed
               5 c1 timer completed

I know I could rewrite this to get it to work without using disable, but it’s such an easy way to terminate a task early that I’m hoping there is something I’m missing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:13:28+00:00Added an answer on June 12, 2026 at 8:13 am

    I don’t think this is possible. Even using disable on named blocks will still stop all instances of that task.

    Disabling an automatic task or a block inside an automatic task
    proceeds as for regular tasks for all concurrent executions of the
    task.

    You could try to use a process class. I’ve never used them myself so this code likely contains errors.

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a SystemVerilog monitor that extends ovm_monitor and I'd like to know
I'm trying to write a synthesizable 3D rasterizer in Verilog/SystemVerilog. The rasterizer right now
I am using SystemVerilog. My code is: function write_pixel_data(datastr ds); /* some stuff here...
I'd like to create a const object inside my SystemVerilog class. Does SystemVerilog support
I have some self-testing code for my SystemVerilog component and I want to ensure
I work on a high-level simulator written in C++ for some hardware that is
Looking at some code I'm maintaining in System Verilog I see some signals that
C rand() and srand() functions is very useful when you doing something like that:
Good Day and thanks for looking at this question I am using VCSMX (a
Hi and thanks for seeing this. I was pondering over the idea of an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.