[fpc-pascal] writeln: FPC runtime race conditions in external C threads
Michael Van Canneyt
michael at freepascal.org
Mon Jul 12 13:24:34 CEST 2010
Basically, any heap memory access and standard pascal I/O are forbidden in
threads started outside FPC, because the necessary thread structures are not
initialized correctly.
Michael.
On Mon, 12 Jul 2010, Alexander Grau wrote:
> Hello,
>
> While using an external C framework (Mac OS X, discrecording OS framework,
> FPC 2.4), I noticed that my FPC console app crashes when I use writeln's in
> both C threads (callbacks).
>
> Example: Two FPC functions that are called from an external C library
> (c_callback1 and c_callback2) - callback2 is called within callback1 in
> another C thread (other than the FPC main thread).
>
>
> // called from external C framework within the FPC main thread
> c_callback1; cdecl;
> begin
> writeln('callback1begin');
> // c_ callback2 is called here from another C thread
> writeln('callback1end'); <== my FPC console app crashes here (
> "EInOutError - Disk Full")
> end;
>
>
> // called from external C framework in another C thread
> c_callback2; cdecl;
> begin
> writeln('callback2begin');
> writeln('callback2end');
> end;
>
> An unhandled exception occurred at $000669E3 :
> EInOutError : Disk Full
> $000669E3 CALLBACK1, line xxx
>
>
> Question: Why isn't it safe to call writeln's in non-FPC threads? Are
> there any other FPC runtime functions I should not call within non-FPC
> threads?
>
> I'm going to make an FPC wiki page ('Threading Pitfalls') that will discuss
> these and other issues related to threading and I welcome all explanations on
> this so I can better understand this problem! :-)
>
> Thanks,
> Alexander
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list