[fpc-pascal] writeln: FPC runtime race conditions in external C threads
Alexander Grau
alex at grauonline.de
Mon Jul 12 12:58:56 CEST 2010
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
More information about the fpc-pascal
mailing list