[fpc-pascal] CloseThread needed? still unclear

noreply at z505.com noreply at z505.com
Mon Nov 14 02:32:17 CET 2011


While testing an updated version of nYume (aservia) I found that the
program is leaking thread handles on Ms Windows. The program uses
BeginThread and EndThread calls.

However, when I add CloseThread() right before EndThread(, the program no
longer leaks handles. So, CloseThread may be needed on Ms Win machines. I
don't think (all) the docs state to call closethread. If CloseThread
should be called on Ms windows, then this makes cross platform threading
difficult since windows requires something different than unix.

I don't know if the object oriented TThread uses CloseThread in it's
backend code and don't know if TThread leaks, I was just trying
beginthread and endthread style.

To find handle leaks, I simply use Windows Task Manager to monitor the
processes, with the Handles column visible. I am also trying some other
tools like DrMemory.

First I thought I would post this to the mailing list to ask you what the
proper way to program with threads is. If we must call closethread on MS
Win machines but not unix machines, then something needs to change to make
the threading in the RTL more cross platform (and all the docs would need
to mention things about closethread if it is needed).

The compiler is 2.4.2 and 2.4.4 that i am using.

The documentation is here:
http://www.freepascal.org/docs-html/prog/progse44.html#x217-23000010.2

But there is also more documentation elsewhere, such as the RTL docs.

I guess I could look into Delphi to see how they use closethread. in their
backend somewhere.



More information about the fpc-pascal mailing list