Thursday, June 10, 2010

semaphore, mailbox and event


semaphore

a semaphore is a bucket to store 1 or more keys. Any process using semaphore must procure a key before it can continue to execute.
To declare a semaphore:
semaphore smTx
Semaphore is a built-in class that provides the following methods:
Create a semaphore with a specified number of keys:
function new(int keyCount = 0 );
Obtain one or more keys from the bucket. If the specified number of keys is not available, the process blocks until the keys become available.
task get(int keyCount = 1);
Return one or more keys into the bucket. If the specified number of keys is available, the method returns a positive integer and execution continues.
task put(int keyCount = 1);
Try to obtain one or more keys without blocking. The semaphore try_get() method is used to procure a specified number of keys from a semaphore, but without blocking.
function int try_get(int keyCount = 1);

mailbox
A mailbox is a communication mechanism that allows messages to be exchanged between processes. Data can be sent to a mailbox by one process and retrieved by another.
Conceptually, mailboxes behave like real mailboxes.
  When a letter is delivered and put into the mailbox, one can retrieve the letter (and any data stored within). However, if the letter has not been delivered when one checks the mailbox, one must choose whether to wait for the letter or to retrieve the letter on a subsequent trip to the mailbox. Similarly, SystemVerilog's mailboxes provide processes to transfer and retrieve data in a controlled manner.
size: Mailboxes are created as having either a bounded or unbounded queue size.
      A bounded mailbox becomes full when it contains the bounded number of messages. A process that attempts to place a message into a full mailbox shall be suspended until enough room becomes available in the mailbox queue.
      Unbounded mailboxes never suspend a thread in a send operation.

An example of creating a mailbox is as follows:
mailbox mbxRcv;

Mailbox is a built-in class that provides the following methods:
Create a new mailbox
  function new(int bound = 0);
If the bound argument  is  0,  then  the  mailbox  is  unbounded

The number of messages in a mailbox can be obtained via the num() method.
  function int num();

The put() method places a message in a mailbox.
  task put( singular message);
The message  is any singular expression, including object handles.
If the mailbox was created with a bounded queue, the process shall be suspended until there is enough room in the queue.

The try_put() method attempts to place a message in a mailbox.
  function int try_put( singular message);
The try_put()  method stores a message in the mailbox in strict FIFO order. Meaningful only for bounded mailboxes. If the mailbox is full, the method returns 0.

The get() method retrieves a message from a mailbox.
task get( ref singular message );
  The get()  method retrieves one message from the mailbox, that is, removes one message from the mailbox queue. If the mailbox is empty, then the current process blocks until a message is placed in the mailbox.

try_get() method attempts to retrieves a message from a mailbox without blocking.
  function int try_get( ref singular message );

The peek() method copies a message from a mailbox without removing the message from the queue.
  task peek( ref singular message );
The peek()  method copies one message from the mailbox without removing the message from the mailbox queue.

The try_peek() method attempts to copy a message from a mailbox without blocking.
  function int try_peek( ref singular message );



Event
 Nonblocking event trigger are supported in systemverilog  using the ->> operator.
 The basic mechanism to wait for an event to be triggered is via the event control operator, @.
@ hierarchical_event_identifier;

SystemVerilog can distinguish the event trigger itself, which is instantaneous. The triggered property is invoked using a method-like syntax:
hierarchical_event_identifier.triggered.
The triggered event property is most useful when used in the context of a wait construct:
wait ( hierarchical_event_identifier.triggered )

No comments: