Mail_boxes
Mail_boxes
bounded mailbox
unbounded mailbox
A bounded mailbox is with the size defined. mailbox becomes full when on
storing a bounded number of messages. A process that attempts to place a
message into a full mailbox shall be suspended until enough space
becomes available in the mailbox queue.
Mailbox types
Generic Mailbox
Parameterized mailbox
The default mailbox is type-less. that is, a single mailbox can send and
receive data of any type.
mailbox mailbox_name;
Mailbox Methods
new( );
mailbox_name = new(m_size); //Creates bounded mailbox with size m_size and returns
mailbox handle ,where m_size is integer variable
//-------------------------------------------------------------------------
// Packet
//-------------------------------------------------------------------------
class packet;
$display("Packet::Packet Generated");
$display("Packet::Addr=%0d,Data=%0d",addr,data);
endfunction
endclass
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
class generator;
packet pkt;
mailbox m_box;
this.m_box = m_box;
endfunction
task run;
repeat(2) begin
pkt = new();
#5;
end
endtask
endclass
//-------------------------------------------------------------------------
// Driver - Gets the packet from generator and display's the packet items
//-------------------------------------------------------------------------
class driver;
packet pkt;
mailbox m_box;
this.m_box = m_box;
endfunction
task run;
repeat(2) begin
$display("Driver::Packet Recived");
$display("Driver::Addr=%0d,Data=%0d\n",pkt.addr,pkt.data);
end
endtask
endclass
//-------------------------------------------------------------------------
// tbench_top
//-------------------------------------------------------------------------
module mailbox_ex;
generator gen;
driver dri;
initial begin
//Creating the mailbox, Passing the same handle to generator and driver,
$display("------------------------------------------");
fork
gen.run(); //Process-1
dri.run(); //Process-2
join
$display("------------------------------------------");
end
endmodule
Simulator Output
------------------------------------------
Packet::Packet Generated
Packet::Addr=3,Data=38
Driver::Packet Recived
Driver::Addr=3,Data=38
Packet::Packet Generated
Packet::Addr=118,Data=92
Driver::Packet Recived
Driver::Addr=118,Data=92