TLazThreadedQueue.Grow may loose items in the queue
Original Reporter info from Mantis: Martin @martin_frb
-
Reporter name: Martin Friebe
Original Reporter info from Mantis: Martin @martin_frb
- Reporter name: Martin Friebe
Description:
TLazThreadedQueue.Grow starts with FMonitor.Enter;
Therefore it is apparently meant to be used, once the queue is in action (i.e. the method is threadsave, threadsave access is expected once the threats will push and pop items.)
But, modifying the queue-size, without adjusting FTotalItemsPushed / FTotalItemsPopped means:
The position of the current item FList[FTotalItemsPopped mod FQueueSize] changes. So any further "pop" will get random data.
The following could fix this, but there are public properties to access those values. So user apps would no longer get the expected values.
procedure TLazThreadedQueue.Grow(ADelta: integer);
begin
FMonitor.Enter;
try
FTotalItemsPushed := FTotalItemsPushed mod FQueueSize;
FTotalItemsPopped := FTotalItemsPopped mod FQueueSize;
FQueueSize:=FQueueSize+ADelta;
setlength(FList, FQueueSize);
if FTotalItemsPopped > FTotalItemsPushed then inc(FTotalItemsPopped, FQueueSize);
finally
FMonitor.Leave;
end;
end;
The other option is to shift all items.
That would benefit "Grow(-10)" which shrinks the queue.
Mantis conversion info:
- Mantis ID: 37612
- OS: win 10
- OS Build: 10
- Platform: 64bit Intel
- Version: 2.1 (SVN)
- Fixed in version: 2.2
- Fixed in revision: 63811 (#b61fd4c9)
- Target version: 2.2