hi all!
i have a class T, which containes random variables. i randomize it in class A, and then send it to classes B and C via mailboxes, like this:
Class A;
T t;
task run();
t = new();
assert(t.randomize);
mbx_A_B.put(t);
mbx_A_C.put(t);
endtask
endclass
Class B;
T t;
task run();
mbx_A_B.get(t);
//other code
endtask
endclass
But if i change in class B variable, located in object t (class T) after receiving it, it automatically changes in C too. So i don’t really “send” it from one object to another, but only make a reference to it, am i right? and if i do, how can i avoid this?
You are correct in that a mailbox will pass by reference. In order to prevent mutual interference, you should create a clone of the object prior to placing it in the mailbox.
The example that you are looking at isn’t very complete in that the copy() function will only create a new sub-class and not actually copy the values as you desire.
Take a look at the UVM Transaction Methods page to get a better understanding of a copy function. While this is for a uvm_object, the concepts are the same.