“Mario Charest” <goto@nothingness.com> wrote in
news:abchat$e6r$1@inn.qnx.com:
Don’t know if it’s related to your problem but last time I checked,
sleep wasn’t thread safe.
Mario, you’re missing the point here:
THE THREAD NEVER GETS TO MY CODE!
Try this even simpler test case with the -3s compiler switch:
– test.c —
#include <stdio.h>
#include <process.h>
void mythread(void *arg)
{
}
int main(int argc, char argv[])
{
_beginthread(mythread,NULL,321024,NULL);
return 0;
}
cc test.c # default (register) calling
a.out # should work
cc -3s test.c # stack calling convention
a.out # will SEGV
Put a breakpoint on mythread() and it’ll never hit.
I’ve investigated further, and found that the Watcom begin_thread_healper()
routine in clib3s expects the thread argument to arrive on the stack, but
the tfork() routine sends it in register eax. I replaced the
begin_thread_helper() routine (found in the clib3s threadqnx module) and
everything works fine.
Ancient Deja searches show that a few other people have run across this
same issue, but every time they’ve asked for help they’ve gotten the same
sort of “threads are nasty” answers. At least Renee offered to try to
replicate the behavior, and I’m curious as to what happened there. Who
knows, maybe it’s a bad copy of the clib3s library on my QNX CD. Unlikely,
but possible.
I don’t suppose it matters anyway, since QSSL has clearly shown that they
aren’t interested in fixing QNX4/Watcom issues. Not that I blame them–
they’re full speed on RTP and I’d rather have most of their time go there
anyway. (I imagine we’ll be giving it another try when 6.2 finally
releases, but 6.1 was still a bit too rough around the edges for us on this
project.)
Anyway, sorry if I was a bit harsh above, Mario. I know that you’ve
provided good help to a lot of people on this group. And yes, I know that
multithreaded apps can be tricky and most (almost all?) problems are
really programmer errors. However, this one really is caused by a clib3s
bug.
Good call on the sleep() not being thread-safe. I had added it into the
test code because of a Watcom thread startup problem I seem to remember,
where threads that executed and returned too quickly caused some sort of
problem. I tossed in the sleep() to see if it would help, but then I
later realized that the SEGV was popping up before mythread() was even
called.