Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-09

TThread.CurrentThread fails on Linux

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mario R. Carro

Hello all.

In it's current form (r23227) CurrentThreadVar it's not initialized before calling Execute in the TThread implementation for Linux (Unix).

Due to this the calls to TThread.CurrentThread always returns references to TExternalThread instances, guessing that the current thread is not a FPC thread (due to CurrentThreadVar being nil), even for actual TThread threads.

Adding the line:

	CurrentThreadVar := LThread;

somewhere before calling Execute in ThreadFunc in rtl/unix/tthread.inc solves this problem.

Also: the TExternalThread instances created by TThread.CurrentThread are never freed, and so effectively leaked, isn't it?

Thanks,
Mario

Reply by email

Sven Barth
to Mario R. Carro
Mario R. Carro wrote 16 lines
Hello all. In it's current form (r23227) CurrentThreadVar it's not initialized before calling Execute in the TThread implementation for Linux (Unix). Due to this the calls to TThread.CurrentThread always returns references to TExternalThread instances, guessing that the current thread is not a FPC thread (due to CurrentThreadVar being nil), even for actual TThread threads. Adding the line: CurrentThreadVar := LThread; somewhere before calling Execute in ThreadFunc in rtl/unix/tthread.inc solves this problem.

Why the hell does the Unix implementation use a different thread function which does the same in the end?! O.o
Please create a bug report.

Also: the TExternalThread instances created by TThread.CurrentThread are never freed, and so effectively leaked, isn't it?

They are freed at the end of the program.

Regards,
Sven

Reply by email