ch5-Semaphore
2019-10-30
SystemVerilog Semaphore
Semaphore is just like a bucket with a fixed number of keys. Processes that use a semaphore must first get a key from the bucket before they can continue to exectute. Other proceses must wait until keys are available in the bucket for them to use. In a sense, they are best used for mutual exclusion, access control to shared resources and basic synchronization.
Syntax
1 |
|
Note that semaphore
is a built-in class and hence it should be used just like any other class object. It has a few methods with which we can allocate the number of keys for that semaphore
object, get and put keys into the bucket.
Methods
Name | Description |
---|---|
function new (int keyCount = 0); | Specifies number of keys initially allocated to the semaphore bucket |
function void put (int keyCount = 1); | Specifies the number of keys being returned to the semaphore |
task get (int keyCount = 1); | Specifies the number of keys to obtain from the semaphore |
function int try_get (int keyCount = 1); | Specifies the required number of keys to obtain from the semaphore |
Example
1 |
|
Simulation Log
1 |
|
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!