Note that there are some explanatory texts on larger screens.

plurals
  1. PODelphi Parallel programming - multi threading slow
    text
    copied!<p>Good day,</p> <p>A webcam class has about 30 frames per second, and all of these frames will be saved in a vector(like a queue). Then 3 asynchronous threads will read the queue, and will try to do their jobs(to save these images). Why the queue is overflowing? So the problem is that these threads are slower than the webcam. </p> <pre><code>Procedure TSaveThread.Execute; begin while not terminated do begin elElement:=NIL; EnterCriticalSection(CritSect); if iElementsLength&gt;=0 then begin elElement:=vElements[iElementsLength]; Dec(iElementsLength); end; LeaveCriticalSection(CritSect); if elElement&lt;&gt;NIL then begin JpegImg.Assign(elElement.bmWebcam) ; JpegImg.SaveToFile('Save\'+elElement.sTime+'.jpg') ; elElement.Free; end; Sleep(20); end; end; </code></pre> <p>Images added to the queue.</p> <pre><code>//------------------------------------------------------------------------------ Procedure TWebcam.OnSave(Sender:TObject; bmWebcam:TBitmap); begin EnterCriticalSection(CritSect); inc(iElementsLength); vElements[iElementsLength]:=TElement.Create(bmWebcam); LeaveCriticalSection(CritSect); end; </code></pre> <p>Creating the threads.</p> <pre><code>for i:=0 to 2 do TSaveThread.Create(false); </code></pre> <p>The thing is that, these threads are not able to save all these images. Why? How can I improve my threads?</p> <p>Delphi Version: Delphi XE2</p> <p>Webcam frame size: 1280x760 or 960x600 Entire source code here: <a href="http://pastebin.com/8SekN4TE" rel="nofollow">http://pastebin.com/8SekN4TE</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload