Giuliano Colla wrote:
> willem ha scritto:
> > well I made 10 copy's of threadbug and run them in parallel. In my
> > case libpthread does not allocate a 10 Mb memory block, because
> > the 10 processes should allocate 100Mb of memory Top does show only a
> > sligth increase in memory . On my kubuntu there are
> > 145 processes allocated . So i can not reproduce your problem.
:
:
> I've modified threadbug to activate many threads instead if just one.
> I show you the results with 300 threads.
>
> Thats Top report when threadbug is started:
> Mem: 1024940k total, 496500k used, 528440k free, 22416k buffers
> Swap: 1028152k total, 0k used, 1028152k free, 312576k cached
> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
> 4227 colla 17 0 2548 788 488 S 0 0.1 0:00.00 threadbug
>
> That's the output of Top after 300 threads have been activated:
> Mem: 1024940k total, 501224k used, 523716k free, 22664k buffers
> Swap: 1028152k total, 0k used, 1028152k free, 312708k cached
> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
> 4227 colla 24 0 3004m 3300 520 S 0 0.3 0:00.08 threadbug
>
> You can see that memory usage has minimally changed, from 496500k to
> 501224, but you can also see that the virtual memory allocated to
> threadbug has jumped from 2548k to 3004m (i.e. 3Gb!).
>
> That's Top output after the 300 threads have been destroyed:
> Mem: 1024940k total, 535096k used, 489844k free, 24288k buffers
> Swap: 1028152k total, 0k used, 1028152k free, 334308k cached
> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
> 4227 colla 15 0 33364 988 576 S 0 0.1 0:01.20 threadbug
>
> You can see that total memory usage has increased instead of decreasing,
> because some allocated memory has been actually used, but what's more
> important, you can see that virtual memory allocated to threadbug is
> 33364 kB instead of the initial 2254.
Great analysis!
So if you see this problem on fpc2.2.0 even with WaitFor, then this is a
regression on top of the bug, because your multithread.lpr runs without
leaks using fpc2.0.2.
To get the leak on fpc2.0.2 you have to change your code like this:
for I := 0 to high(BugArray) do begin
t1 := BugArray[I];
t1.Terminate;
- t1.WaitFor;
write ('.'); // this causes intermittent idles causing the leak
if not Ft then begin
sleep(50);
t1.Free;
end;
end;
...and...
writeln('WaitFor? [y/N]');
+ t1.Terminate;
readln(ans); // you need to idle after terminate to see the leak
- t1.Terminate;
if ans='y' then begin
if not Ft then begin
t1.WaitFor;
writeln('OS thread memory released.');
end;
end else
writeln('OS thread memory left dangling.');
Also note that when you TThread.Free a running thread it will do an implied
Terminate and WaitFor, and therefore works without leaking on fpc2.0.2.
Thanks!
--
Al
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives