Skip to content

SystemVerilog · Topic

SystemVerilog Tasks & Functions

Tasks, functions, automatic versus static lifetime, arguments, return values and void functions — the subroutine rules that decide reuse and re-entrancy.

The distinction that matters is not syntax but time: a function cannot consume simulation time, and a task can. Everything else follows — a function may be called from an expression, a task may not, and a task that blocks inside a loop changes when its caller resumes. The second trap is lifetime: a static task shares its locals across every concurrent call, so two threads calling the same driver task corrupt each other's state in a way that looks like a race in the DUT.

Lessons in this topic(7)

Start hereTasks vs. Functions — When to Use WhichSystemVerilog Tasks vs. Functions — When to Use Which
  1. 2Function Declarations & Return Values
  2. 3Task Declarations & Time-Consuming Calls
  3. 4Automatic vs. Static Lifetime
  4. 5Pass by Value vs. Pass by Reference
  5. 6Default Argument Values
  6. 7void Functions & System Tasks Overview