I've observed a weird behavior with FPC 3.1.1 trunk and Linux.
Using htop + user threads showing on a server program, a lot of threads are listed, even if they are not active any more.
Looking in details, I discovered that in rtl/unix/tthread.inc, ThreadFunc() doesn't call EndThread if FreeOnTerminate=false.
function ThreadFunc(parameter: Pointer): ptrint;
var
....
LFreeOnTerminate := LThread.FreeOnTerminate;
LThread.DoTerminate;
LThread.FFinished := True;
if LFreeOnTerminate then
begin
WRITE_DEBUG('Thread ',ptruint(lthread),' should be freed');
LThread.Free;
WRITE_DEBUG('Thread freed');
WRITE_DEBUG('thread func calling EndThread');
// we can never come here if the thread has already been joined, because
// this function is the thread's main function (so it would have terminated
// already in case it was joined)
EndThread(Result);
end;
end;
So no pthread_detach/pthread_exit() seems to be called.
What did I miss?
I can't find the source of this resource leak, which could be very difficult with serious multithreaded process on a Linux server...