Associative array access from two tasks

I have a fundamental question.

Can there be two functions that write to the same associative array[key] ?
Problem I am trying to solve is multiple masters writing to the same addresss with different data fields, I would like to store in an associative array.

Thanks.

In reply to UVM_learner6:

You can pass an associative array by reference to a function. Since you are using there UVM, it provide a uvm_pool class, which is essentially an associative array wrapped in a class. The you just pass the function/task a handle to the class.

In reply to dave_59:

Hi Dave,

Could you please provide an example reference for passing associative array by reference to the function?

So if the task that does the storing of information into associative array is called

virtual task store_write_transaction(ref packet);


and then from other tasks, I can call it as : store_write_transaction(packettype2) or store_write_transaction(packettype2)

My doubt is that both masters are using the same “key” (address in this case, both are writing to the same address) and when a transaction appears on the outside of DUT, I want to compare with my predicted trans[addr]. So if the key is the same, do I need to have a associative array of queues?

Please let me know if I am missing something.

do you want to store the data of both the master using the same key ?
if yes then you should have master id also as key along with addr.


//trans_type aa [master_id][addr] 
trans_type aa [int][int]; 

if you don’t have master_id as key then you can’t differentiate data stored for master 0 or master 1 as it have only last written data for specific key.


//trans_type aa addr] 
trans_type aa [int]; 

//store master 0,  data=0x1234 for addr=10
aa[10] = 0x1234;
//store master 0,  data=0x5678 for addr=10
aa[10] = 0x5678 ;

//master 0 data is lost as it was overwritten by the master 1 data
$display(aa[10]); // 0x5678