Here is some sample code in Delphi (D7), a single form with:
1 tspinedit, 1 tmemo, 1 tbutton, 1 TJvMTManager, and 1 TJvMTThread
procedure TForm1.JvMTThread1Execute(Sender: TJvMTThread; MTThread: TJvMTSingleThread);
FOR X:=1 TO 100000 DO BEGIN
//if (x mod 10)=0 then
application.processmessages; // doesnt make a difference in the results
st:='test'; //test code
st:=ansiuppercase(st); //test code
st:=ansilowercase(st); //test code
procedure TForm1.Button1Click(Sender: TObject);
for x:=1 to SpinEdit1.value do
I found the issue with TThread, and then I got the same results with TJvMTThread.
The issue is shown in the results:
1 single thread runs at ~200ms
2 threads results in ~2600ms (more than 6 times of what it should be?)
4 threads ~5500 ms
In no moment CPU usage goes over %50, even when setting thread priority to real_time.
Now, those numbers could be lowered significantly by using a criticalsection.enter / leave (For instance, 2 threads should run at ~400ms) but that's not the way threads should work.
The way I want threads to work is exactly the same way as when executing this application twice and running it in sync, resulting them both running at ~200ms.
Something else about threads I don't know?