Mailbox

In reply to dave_59:

i’m learning how mailboxes work so as an example i have considered an alu block and by using mailbox im accessing the inputs.
is it right way to do ?

i want to access my mailbox everytime my inputs(opcode op1,op2 ) changes at #1 time .

class driver;
  stimulus sti;
  mailbox m_box;
  
  //constructor, getting mailbox handle
  function new(mailbox m_box);
    this.m_box = m_box;
  endfunction
  
  task run;
    repeat(5) begin
      m_box.get(sti); //getting stimulus from mailbox
      $display("Driver:: stimulus is received at %g",$time);
      $display("[Driver]:stimulus is generated :: op1 = %d , op2 = %d , opcode = %d %d",sti.op1,sti.op2,sti.opcode,m_box.num());
     
    end
  endtask
endclass