In reply to ocmob:
Yeah but how we can access all the element from the queue.It will always loop the zero’th element I guess.
Here I am attaching my code please have a look.
module test;
int result ,result_1;
class mailbox #(type T = bit);
T que [$];
task put(input T item);
que.push_back(item);
endtask
task get(output T item);
wait(que.size > 0);
item = que.pop_front();
endtask
task peek(output T item);
wait(que.size > 0);
for(int i; i < que.size -1 ;i ++)
item = que[i];
$display("item =%0d",item);
endtask
endclass
class A;
mailbox #(int) mbx;
rand bit[3:0] data [];
constraint abc {data.size == 10;}
function new();
mbx = new;
endfunction
endclass
A a1,a2;
initial begin
a1 = new();
a1.randomize ();
foreach(a1.data[i])
a1.mbx.put(a1.data[i]);
$display(a1.mbx);
fork
//forever begin
//a1.mbx.get(result);
//$display($time,"Result = %0d",result);
//$display(a1.mbx);
//#10;
//end
forever begin
a1.mbx.peek(result_1);
$display($time,"Result_1 = %0d",result_1);
$display(a1.mbx);
end
join
end
endmodule