[fpc-pascal] problem with threads and backgrounding, fpc 2.1.3 arm native

Luca Olivetti luca at ventoso.org
Tue Apr 3 17:33:25 CEST 2007


[I'm not sure if this should go here or fpc-devel]

Hello,
I'm quite impressed by the native arm compiler that I grabbed here
ftp://ftp.freepascal.org/pub/fpc/beta/2.1.2/arm-linux/.
My small but relatively complex program (with various threads using 
synchronize and critical sections, c library with callbacks to pascal, 
etc.) is working flawlessly in the foreground, but it segfaults if I try 
to background it (or try to use fpFork), and this is a problem since I 
want to write a daemon (i can use screen though if that isn't possible).

This small program exhibits the same problem:

---8<-------8<-------8<-------8<----------
program test;
{$mode objfpc}{$H+}

uses cthreads,sysutils,classes;

type
   tmt=class(TThread)
     procedure execute;override;
   end;

var
   mt:tmt;

procedure tmt.execute;
begin
   while not terminated do sleep(100);
end;

begin
   mt:=tmt.create(false);
   sleep(5000);
   write('press enter to finish');
   readln;
   mt.free;
end.
---8<-------8<-------8<-------8<----------

If you try to bacground it with ctrl+z during the sleep(5000) it will 
segfaults:

luca at lspro:~/fork$ ./test

[1]+  Stopped                 ./test
luca at lspro:~/fork$ fg
./test
An unhandled exception occurred at $BEE2C9C8 :
EAccessViolation : Access violation
   $BEE2C9C8
   $000103B0


If you remove the thread or try to background it after the sleep there's 
no problem. Also the same program under i386 (but compiled with fpc 
2.0.4) has no such problem.
I'm running it on a linkstation pro with freelink (debian etch):

luca at lspro:~$ cat /proc/cpuinfo
Processor       : ARM926EJ-Sid(wb) rev 0 (v5l)
BogoMIPS        : 266.24
Features        : swp half thumb fastmult edsp java
CPU implementer : 0x41
CPU architecture: 5TEJ
CPU variant     : 0x0
CPU part        : 0x926
CPU revision    : 0
Cache type      : write-back
Cache clean     : cp15 c7 ops
Cache lockdown  : format C
Cache format    : Harvard
I size          : 32768
I assoc         : 1
I line length   : 32
I sets          : 1024
D size          : 32768
D assoc         : 1
D line length   : 32
D sets          : 1024

Hardware        : MV-88fxx81
Revision        : 0000
Serial          : 0000000000000000

luca at lspro:~$ uname -a
Linux lspro 2.6.12.6-arm1 #77 Tue Dec 5 22:23:46 CST 2006 armv5tejl 
GNU/Linux


Bye
-- 
Luca

A: Because it destroys the flow of the conversation
Q: Why is it bad?
A: No, it's bad.
Q: Should I top post in replies to mailing lists?



More information about the fpc-pascal mailing list