What is the difference between a mailbox and a queue in SystemVerilog?
What is the difference between a mailbox and a queue in SystemVerilog?
Model answer
A mailbox is a communication mechanism between processes. A queue is a data structure with no built-in synchronization. A mailbox has these properties: A built-in class, which must be created with new(). put() blocks only if a bounded mailbox is full, and get() blocks while it is empty. Non-blocking try_put() and try_get() are also available. Messages come out in FIFO order, and each message goes to one receiver. It can have multiple senders and receivers. A queue has these properties: A variable-size array type, which needs no new(). Its methods, such as push_back() and pop_front(), never block. Popping an empty queue returns the default value, so a reader must wait by other means. Any element can be accessed by index. Use a mailbox to pass transactions between concurrent components, such as a generator and a driver. Use a queue to store data, such as expected values in a scoreboard.