* Problems with gcc and cma threads on HP-UX 10.20
@ 2000-07-20 7:01 Guenter Obiltschnig
0 siblings, 0 replies; only message in thread
From: Guenter Obiltschnig @ 2000-07-20 7:01 UTC (permalink / raw)
To: gcc
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>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2000-07-20 7:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-20 7:01 Problems with gcc and cma threads on HP-UX 10.20 Guenter Obiltschnig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).