[fpc-pascal] problem with threads and backgrounding, fpc 2.1.3 arm native
Luca Olivetti
luca at ventoso.org
Thu Apr 5 00:11:54 CEST 2007
En/na Luca Olivetti ha escrit:
> OTOH my real program, even if cross-compiled (what a pain!), is still
> throwing an exception if I use ctrl-z, is still having problems with
> fork but at least (if I leave it in the foreground) I can use ctrl+c.
This is another test program that shows my problem with fork: as soon as
I start the thread, the main program stops working (the thread *is*
running, you can put a writeln in its loop to show it). Note that in
this short example I don't close stdin,stdout,stderr, I don't block
signals but it doesn't matter (I did it all and the result is the same).
The same happens with the native compiler and the cross compiler.
Now, if I remove the fork part, both the thread and the main loop work,
but if I use crtl-z and then fg after the thread has started it will
give an EAccessViolation, but this only with the native compiler (remind
that the native compiler is 2.1.3 while the cross compiler is 2.0.4).
---------8<--------8<-------8<--------8<----------
program test2;
{$mode objfpc}{$H+}
uses cthreads,sysutils,classes,baseunix;
type
tmt=class(TThread)
procedure execute;override;
end;
var
mt:tmt;
t:TPid;
i:integer;
procedure tmt.execute;
begin
while not terminated do sleep(1000);
end;
begin
t:=FpFork;
if t<0 then
begin
writeln('fork failed');
halt(t);
end;
if t>0 then Halt(0); //parent
while true do
begin
i:=i+1;
writeln('running ',i);
sleep(1000);
if i=5 then mt:=tmt.create(false);
end;
end.
---------8<--------8<-------8<--------8<----------
Bye
--
Luca
More information about the fpc-pascal
mailing list