[fpc-pascal] writeln: FPC runtime race conditions in external C threads

Michael Van Canneyt michael at freepascal.org
Mon Jul 12 23:04:31 CEST 2010



On Mon, 12 Jul 2010, Jonas Maebe wrote:

> Alexander Grau wrote on Mon, 12 Jul 2010:
>
>> Am 12.07.2010 um 22:31 schrieb Jonas Maebe:
>> 
>>> I forgot to mention: before this works, you have to create at least one 
>>> thread using the FPC RTL in order to initialise the threading subsystem. 
>>> It can be terminated/freed immediately, see the test program that was 
>>> committed together with the fix for an example.
>> 
>> That did the trick!  Seems to work -  I'm really curious how this works, 
>> since I assume there's probably no control over how the external C thread 
>> is created and so no chance to initialize something for the FPC runtime ...
>
> The FPC runtime support for such a thread is initialised the first time you 
> access a threadvar from that thread. And there's also a way to make 
> libpthread automatically call a "destructor" routine when such a thread 
> finishes (that's what I discovered today, and which was the missing piece of 
> the puzzle).

Jonas, if only I had known these 2 little details 5 years ago, when I needed
it for Apache module support :/

Thank you very much. This is a great step forward !!

One small detail : maybe we should create a call 'inittheading' or make the
'IsMultithreaded' variable a property, that, when written, does the
initialization ?

That's a bit cleaner than creating a thread ?

Michael.



More information about the fpc-pascal mailing list