www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Porting GDC to QNX

Sheff Wrote:

 Hi everyone, I'm porting GDC compiler, version 0.23 and GCC 4.1.1 to QNX
Neutrino 6.3.0 SP1 (with GCC 3.3.5).
 The porting is almost done, GDC, GCC and Phobos are compiled and working fine,
but you can't say the same for the programs, which GDC produces from D source
code. So far I tested, I only spot one problem: posix threads. Consider the
following example:
 
 import std.stdio;
 import std.thread;
 
 char[] string;
 
 int th_func(void* arg)
 {
 	const int num = 1_000_000;
 
 	for (int i=0; i<num; ++i)
 	{
 		string ~= "*";
 	}
 
 	return 0;
 }
 
 int main(char[][] args)
 {
 	auto th = new Thread(&th_func, null);
 	scope(exit)
 		delete th;
 
 	th.start();
 	th.wait();
 
 	writefln("end\n");
 
     return 0;
 }
 
 When you run this program, it crashes with signal SIGUSR1, which's generated
by pthread_join(), here's GDB output:
 
 Program received signal SIGUSR1, User defined signal 1.
 [Switching to process 66433068]
 0xb032f092 in ThreadJoin_r () from /usr/qnx630/target/qnx6/x86/lib/libc.so.2
 (gdb) bt
 #0  0xb032f092 in ThreadJoin_r ()
    from /usr/qnx630/target/qnx6/x86/lib/libc.so.2
 #1  0xb031a801 in pthread_join ()
    from /usr/qnx630/target/qnx6/x86/lib/libc.so.2
 Memory fault
 
 But, if you'll replace the line:
 
 const int num = 1_000_000;
 
 with:
 
 const int num = 100_000;
 
 Then everything works fine, the "end" string gets printed, program successfuly
exits. Consider another, similar example:
 
 import std.stdio;
 import std.thread;
 
 char[] string;
 
 int th_func(void* arg)
 {
 	const int num = 1_000_000;
 
 	for (int i=0; i<num; ++i)
 	{
 		string ~= "*";
 	}
 
 	return 0;
 }
 
 int main(char[][] args)
 {
 	th_func(null);
 
 	writefln("end\n");
 
     return 0;
 }
 
 As you can see, we have
 
 const int num = 1_000_000;
 
 here like in first example, which crashed, but this one doesn't, it works fine
even if I write:
 
 const int num = 50_000_000;
 
 The conclusion I made from all this is that there's something wrong with
threads, but I can't figure out what. Does anyone have any ideas ?

I think I understood what's the problem, the values of POSIX constants are different in linux and QNX (i.e O_CREAT, MAP_ANON, etc ), but in phobos they're defined like in linux, for example: In phobos O_CREAT defined like: const int O_CREAT = 0100; //0x64 In linux fcntl.h header: #define O_CREAT 0100 //0x64 but in QNX fcntl.h header it's defined like this: #define O_CREAT 0400 //0x100 0x64 != 0x100, so file creation always fails, so do other system calls. What shall I do about it ? I don't want to manually redefine all POSIX constants...
Mar 30 2007