Question on internals of mailbox built-in class

Hi,
I am curious to know the internal structure of mailbox class :
My understanding is that mailbox is a built-in class, implemented internally with internal data queue and semaphores. If there are multiple threads accessing a mailbox, which is full, the threads will suspend and wake up in the FIFO order as the space becomes available in internal queue and only one thread is allowed to push data into mailbox. While one thread is checking the size of mailbox and pushing data into it, another parallel thread is not allowed to check the size and push data into mailbox i.e. put and get operations are atomic. (Is this internally achieved with the help of semaphores?)

Now my question is : How is the internal implementation of put task member of mailbox done? In case there are multiple threads waiting for the space to become available in internal queue, is the data of all such threads also put in another queue internally till the space becomes available in internal queue? How are the threads internally distinguished from each other? Is each waiting thread also assigned an ID (identifier)?

Also the System verilog LRM mentions that by default, a mailbox is typeless, i.e. it can send or receive any data. I am not clear how a typeless operation is achieved using a normal System verilog Class. Is it some kind of parametrized class?
-sunil

In reply to puranik.sunil@tcs.com:

Yes, you are correct that a mailbox is made up of two semaphores - a put_semaphore and a get_semaphore, plus the queue holding the mailbox data. Each semaphore is in turn made with a queue of process IDs that implements the FIFO thread ordering. SystemVerilog already provides a process class for identifying threads (See 9.7 Fine-grain process control in the 1800-2012 LRM). Semaphore also provide the atomic test-and-set operation.

You can in fact build your own mailbox class using a combination of semaphores and queues. Some people do this because they want to be able to “stuff” extra entries in the mailbox, or examine the other entries in the mailbox.

One thing you can’t do is create a type-less mailbox or extend an existing mailbox class that is type-less. The type-less mailbox is a legacy feature from the Vera language, which did not have parameterized classes. There is really no good reason to use it anymore.

In reply to dave_59:

In reply to puranik.sunil@tcs.com:
You can in fact build your own mailbox class using a combination of semaphores and queues. Some people do this because they want to be able to “stuff” extra entries in the mailbox, or examine the other entries in the mailbox.
One thing you can’t do is create a type-less mailbox or extend an existing mailbox class that is type-less. The type-less mailbox is a legacy feature from the Vera language, which did not have parameterized classes. There is really no good reason to use it anymore.

Thanks Dave for the explanation. I am planning to write my own mailbox class. Can you please provide an example for me or link to it, if you have it already.
rgs,
-sunil

In reply to puranik.sunil@tcs.com:

In reply to dave_59:
Thanks Dave for the link. One small question: The function self() in process class is declared as static. What could be the reason for it?
rgs,
-sunil

In reply to puranik.sunil@tcs.com:
The self() method is static because you don’t have a handle to the process yet. It’s just like the get() method of a singleton class and there is a singleton process object for each thread.