Difference between semaphore and event

Hi Dave,

Can you help with difference between semaphore and event. If both are used for synchronization purpose then where to use what? Please help

In reply to kranthi445:

An named event in SystemVerilog is broadcasting signal without a value. Think of a clock as broadcasting signal in hardware where everyone is looking for the rising edge (@posedge clock) as its event. But you have to go through the process of setting the clock to 0 for some period, and then setting it 1 for some period to get the posedge event.

A named event just requires an instantaneous trigger (->name or ->>name) to signal all the other processes waiting for @name. Since your testbench should be written without timing, you would use an event instead of ever waiting for the rising/falling edge of a signal within your testbench.

A semaphore is a locking mechanism using a set of keys to a shared resource that processes us the get() and put() methods to manage the keys. The shared resource might be to write to a variable or access to a bus.

Both of these constructs are fairly low-level, and the UVM has many higher level constructs for synchronization. So I suggest you avoid them until you have exhausted other possible solutions.

BTW, I happy to answer questions when I have the time, but please don’t directly address them to me so other people have the opportunity :)