Mailbox

How to copy the contents of one mailbox to another mailbox without disturbing the contents in it?Please explain with an example.(any method without using put() and get())and With using put() and get().

In reply to divya.mahajan:

You can use peek() which just gets the contents of mail box but without deleting it.

example mailbox mbox1;
mailbox mbox2;
mbox1 = new();
mbox2 = new();

    for copying mbox1 contents to mbox2 you can use like below.

    mbox2.get(mbox1.peek());

Chaitanya

peek() or try_peek() can be used to copy the info at destination without removing from the mailbox. peek is for blocking and try_peek is for non-blocking.

eg: Use parametrized mailbox so that you don’t get run-time error.

mailbox #(int) m1,m2;
int data;

m1 = new();
m1.put(100);
m2 = m1;
m2.try_peek(data); or m2.peek(data)

There is no way to copy the contents of a SystemVerilog mailbox as a whole. The brute force way to do this would be to get() each element of the mailbox, then put() it back into both the original and new mailbox simultaneously.

A better option is to avoid the need for the copy in the first place Can you do a put() to both mailboxes? If you need the copy only at certain times, you might want to build your own mailbox using a queue and implement a copy method for it.