This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Problems with gcc and cma threads on HP-UX 10.20
- To: gcc at gcc dot gnu dot org
- Subject: Problems with gcc and cma threads on HP-UX 10.20
- From: Guenter Obiltschnig <guenter dot obiltschnig at cpointc dot com>
- Date: Thu, 20 Jul 2000 16:00:01 +0200
Hi,
I have a strange problem with cma threads (HP-UX 10.20) and gcc/g++
(2.95.2, binary distribution from hpux.cae.wisc.edu).
After some experimenting, I was able to reduce the problem to the
following piece of code (compiled with g++ -g -lcma):
#include <pthread.h>
class Foo
{
public:
~Foo() {}
};
void* ThreadMain(void* arg)
{
Foo bar;
struct timespec ts = {1, 0};
pthread_delay_np(&ts);
return NULL;
}
int main(int argc, char** argv)
{
Foo bar;
pthread_t t1;
pthread_t t2;
pthread_create(&t1, pthread_attr_default, ThreadMain, NULL);
pthread_create(&t2, pthread_attr_default, ThreadMain, NULL);
void* result;
pthread_join(t1, &result);
pthread_join(t2, &result);
pthread_detach(&t1);
pthread_detach(&t2);
return 0;
}
The program crashes with a SIGSEGV as soon as the end of main() is
reached and the destructor of bar is to be called. The program does
not crash if I remove either the declaration of bar in main() or in
ThreadMain(). The program also does not crash if I create only one
thread.
After some debugging i observed the following. Here is the
disassembler output of the offending code in main():
;;; return 0;
ldo 4(%r4),%r19
ldw 0(%sr0,%r19),%r20
ldo 4(%r20),%r19
ldw 0(%sr0,%r19),%r20 ;; value of r20 is an invalid address (0 or
something else)
ldw 0(%sr0,%r20),%r21 ;; causes SIGSEGV
;;; more code, finally calls ~Foo
It turned out that the longword pointed to by r19 (which is then
loaded into r20) is modified by the other threads.
Is the code generated by gcc for HPPA not thread-safe? Or am I
missing something?
Any ideas?
Thanks in advance,
--
Guenter Obiltschnig <guenter.obiltschnig@cpointc.com>