TThreadedQueue not capable of multiple consumers?

前端 未结 5 543
灰色年华
灰色年华 2020-11-29 02:11

Trying to use the TThreadedQueue (Generics.Collections) in a single producer multiple consumer scheme. (Delphi-XE). The idea is to push objects into a queue and let several

5条回答
  •  春和景丽
    2020-11-29 02:42

    Your example seems to work fine under XE2, but if we fill your queue it fails with AV on a PushItem. (Tested under XE2 Update1)

    To reproduce, just increase your task creation from 100 to 1100 (your queue depth was set at 1024)

    for i:= 1 to 1100 do fThreadQueue.PushItem( TThreadTaskMsg.Create( i,''));
    

    This dies for me every time on Windows 7. I initially tried a continual push to stress test it, and it failed at loop 30...then at loop 16...then at 65 so at different intervals but it consistently failed at some point.

      iLoop := 0;
      while iLoop < 1000 do
      begin
        Inc(iLoop);
        WriteLn('Loop: ' + IntToStr(iLoop));  
        for i:= 1 to 100 do fThreadQueue.PushItem( TThreadTaskMsg.Create( i,''));
      end;
    

提交回复
热议问题