Porting GDC to QNX

Sheff sheffmail at mail.ru
Wed Mar 28 10:34:01 PDT 2007


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 ?



More information about the Digitalmars-d mailing list