SV Verification Directory

Interprocess communication is a way to communicate between different processes and testbench components. There are three mechanisms:

  1. Events
  2. Mailbox
  3. Semaphore

Semaphore

A semaphore in SystemVerilog is a built-in class used for synchronization. It acts as a container holding a fixed number of keys, which regulate access to shared memory resources. Semaphores are specifically designed to manage and control concurrent access, ensuring that multiple processes can safely interact with shared resources without conflicts.

Semaphore works on principal called mutual exclusion, i.e., two processes cannot occur at the same time.

Syntax

semaphore <semphaore handle>

Semaphore Methods

Similar to the mailbox, the semaphore in SystemVerilog is equipped with methods for its operation. However, it provides only four distinct methods:

MethodDescription
new();creates a semaphore with specified no. of keys, the default no. of keys is zero ‘0’
get();acquires keys from semaphore, the default no. of requrested key is one ‘1’
put();return keys to semaphore, the default no.of keys returned is one ‘1’
try_get();attempts to acquire keys without blocking the execution