[fpc-pascal] cthreads

Michael Van Canneyt michael at freepascal.org
Fri Jul 25 11:15:51 CEST 2014

On Fri, 25 Jul 2014, Juha Manninen wrote:

> I was asked why a threaded application compiles on Linux without "uses
> cthreads" but it does not work.
> cthreads must _always_ be added to uses section.
> I had no answer to that. IMO such errors should be trapped at
> compile-time, not at run-time.
> Could it be fixed somehow?

No, because there is no way to detect that threads are actually used in the program.

The TThread class is a class like any other, with no special treatment.
It is in the classes unit.

The fact that it is there does not mean it is actually used.
That goes for a lot of code.

You don't even need to use the TThread class; 
you can perfectly program threads with just the threadmanager.

In retrospect, Borland made an error declaring tthread in the classes unit.
It should have been put in a separate unit. That would have made detection easier.

> Many people experience the same run-time error about too many
> concurrent threads. They must search the net and ask questions while
> (I guess) the problem could be solved by forcing a compilation error.

Or - for once in their life - people could read the documentation.


It is remarked TWICE that you must include the cthreads unit.

I will add a remark in the classes unit TThread class documentation, 
to make it even more obvious.


More information about the fpc-pascal mailing list