For the below piece of code, which the variable “rdata” is a queue of type packed struct. In the simulation, when the element is deleted from the queue, an unexpected data('{k:0, wait_:1, rid:0, len:0, count:0}) is added at the end of the queue. What could be the possible reason?
class driver;
randc bit [3:0] id,ln;
int ran,cnt,cont,loc;
int i,j;
semaphore s1 = new(1); semaphore s2 = new(1);
struct packed { int unsigned k; bit wait_;bit [(4-1):0] rid;bit [(2-1):0] len;int count;} rdata[$];
task push_channel;
s1.get(1);
@(posedge clk);
rdata.push_back({i,0,id,ln,0});
$display ("%0t DATA PUSHED IN THE QUEUE! Size = %0d", $time,rdata.size);
foreach(rdata[z]) $display("\t%p",rdata[z]);
@(posedge clk);
rdata[i].wait_ = 1'b1;
cnt = cnt + rdata[i].len + 1'b1;
s1.put(1);
i++;
endtask
task delete_channel;
s2.get(1);
wait(rdata[j].wait_);
begin: RANDOM
for(int q=cont;q<cnt;q++) begin
ran = $urandom%(rdata.size);
@(posedge clk);
rdata[ran].count++;
if(check_len(ran)) begin
rearrange(ran);
cont = q; end
@(posedge clk); end
@(posedge clk);
end
s2.put(1);
j++;
$display("============================================================j = %0d",j);
endtask
function bit check_len(int y);
if(rdata[y].count == rdata[y].len+1'b1) begin
$display("\n%0t Rd_data[%0d] is DONE! Size = %0d\n",$time,rdata[y].k,rdata.size);
return 1; end
else return 0;
endfunction
task rearrange(int ind);
$display("\n%0t BEFORE REARRANGE Size = %0d",$time,rdata.size);
foreach(rdata[z]) $display("\t%p",rdata[z]);
rdata.delete(ind);
$display("%0t AFTER REARRANGE Size = %0d",$time,rdata.size);
foreach(rdata[z]) $display("\t%p",rdata[z]);
$display("");
endtask
endclass
driver dr;
initial begin
dr = new;
for(int ii=0;ii<10;ii++)
begin
dr.randomize;
fork
dr.push_channel;
dr.delete_channel;
join_any
end
$finish;
end