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.
Mailbox is a built-in class that provides the following methods:
--Create a mailbox: new()
--Place a message in a mailbox: put()
--Try to place a message in a mailbox without blocking: try_put()
--Retrieve a message from a mailbox: get() or peek()
--Try to retrieve a message from a mailbox without blocking: try_get() or try_peek()
--Retrieve the number of messages in the mailbox: num()
EXAMPLE: program meain ;
mailbox my_mailbox;
initialbegin my_mailbox = new();
if (my_mailbox)
begin fork put_packets();
get_packets();
#10000;
join_any end
#(1000);
$display("END of Program");
end
task put_packets();
integer i;
begin for (i=0; i<10; i++)
begin #(10);
my_mailbox.put(i);
$display("Done putting packet %d @time %d",i, $time);
end end endtask
task get_packets();
integer i,packet;
begin for (int i=0; i<10; i++)
begin my_mailbox.get(packet);
$display("Got packet %d @time %d", packet, $time);
end end endtask endprogram