public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: multithread with egcs/(C++) and RedHat 5.0
@ 1998-04-22 15:21 Kaz Kylheku
  1998-04-22 20:43 ` Torbjörn Eriksson
  1998-04-23 23:23 ` Niku Kaitaniemi
  0 siblings, 2 replies; 8+ messages in thread
From: Kaz Kylheku @ 1998-04-22 15:21 UTC (permalink / raw)
  To: 'Torbjvrn Eriksson', egcs

On Wednesday, April 22, 1998 5:30 AM, Torbjvrn Eriksson 
[SMTP:pt96ter@palantir.proj.ide.hk-r.se] wrote:
> Hello,
>
> First of all, I apologize if this question shouldn't bee here at all.
> I'm quite new at programming threads, so I don't really know if this
> problem is related to egcs at all.
>
> Background: We're 4 students working on a project at University of
> Karlskrona-Ronneby i southern Sweden. We decided to develop our project
> in C++ on a Linux box, (RedHat 5.0). After doing some research we found
> out that gcc ver. 2.7.2 doesn't work with threads, and that egcs would.
>
> Our problem is that system calls like readdir_r and localtime_r causes
> segmention faults, this is a printout from gdb.

Read the LinuxThreads FAQ! You can't use GDB on multi-threaded
programs; it doesn't recongize threads. At best, you can trace the
main thread. (If any other thread hits a breakpoint set in the main
thread, your program will crash). Core files are also of little
value.

> #0  0x4004c93c in __pthread_mutex_lock () at mutex.c:135
> #1  0x4004e28c in __fresetlockfiles () at lockfile.c:87
> #2  0x400a7053 in _IO_fread (buf=0xbffff7a0, size=44, count=1,
> fp=0x804e250)
>     at iofread.c:44
> #3  0x400c546e in __tzfile_compute (timer=1074773704,
>     use_localtime=1074807804, leap_correct=0xbffff860,
> leap_hit=0xbffff8cc)
>     at tzfile.c:283
> #4  0x400c4413 in tzset_internal () at tzset.c:197
> #5  0x400c518c in __tz_convert () at tzset.c:561
> #6  0x400c1c2f in localtime (t=0xbffff8cc) at localtime.c:49
> #7  0x8048f1c in ThreadClass::Notify () at ThreadClass.cc:103
> #8  0x8048e48 in ThreadClass::ScanDir (this=0x804c1d0) at
> ThreadClass.cc:66
> #9  0x8048daa in ThreadClass::Listen (this=0x804c1d0) at
> ThreadClass.cc:44
> #10 0x8048bfe in main () at main.cc:23

See, this trace doesn't tell me anything! It just looks like your
main thread went into a bunch of nested function calls and
finally hit a mutex lock, and stuck there.

The actual program crash might have easily been caused by
another thread in some part of the code that you can only
guess at.

Your only hope is to insert diagnostic statements everywhere
and read the resulting log.

I have written a class that can be used for diagnosing multi-threaded
Linux programs; it will write the diagnostics of each thread into
a separate file, with time stamps and sequence numbers so
that you can trace the scenario of a failure across multiple
threads.

> I do'nt know, but I suspect that we might start the thread in an illegal
> way
>
> pthread_t
> ThreadClass::Run()
> {
>   pthread_attr_init(&myThreadAttr);
>   pthread_attr_setscope(&myThreadAttr, PTHREAD_SCOPE_SYSTEM);
>
>   if (pthread_create(&myThread, &myThreadAttr, SpawnThread, this)==0)

Holy cow, I hope you declared SpawnThread as a static member function.
You can't specify an ordinary member function
as the thread entry point! Member functions are not like ordinary C functions.
They can only be used in conjunction with an object.

You can use a static member function as your thread stub, but to be
absolutely correct, you should use a non-member function declared
extern "C".

> In localtime_r, the program causes a segm. fault
>
> We have installed
> gcc version egcs-2.90.27 980315 (egcs-1.0.2 release)
> and the prerequisits that the rpm asked for.

Are you using exception handling? Which libc are you using?
For threaded programming you should use glibc2, which incorporates
LinuxThreads. You can also get away with libc5, as long as you
have properly installed Linuxthreads 0.7x over top of it.

If you want threads to throw exceptions, you have to use a
developmental EGCS snapshot rather than a released version,
and go through some magic incantations to build the
thread-safe exception handling.


^ permalink raw reply	[flat|nested] 8+ messages in thread
* multithread with egcs/(C++) and RedHat 5.0
@ 1998-04-22  8:31 Torbjörn Eriksson
  0 siblings, 0 replies; 8+ messages in thread
From: Torbjörn Eriksson @ 1998-04-22  8:31 UTC (permalink / raw)
  To: egcs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2735 bytes --]

Hello,

First of all, I apologize if this question shouldn't bee here at all.
I'm quite new at programming threads, so I don't really know if this
problem is related to egcs at all.

Background: We're 4 students working on a project at University of
Karlskrona-Ronneby i southern Sweden. We decided to develop our project
in C++ on a Linux box, (RedHat 5.0). After doing some research we found
out that gcc ver. 2.7.2 doesn't work with threads, and that egcs would.

Our problem is that system calls like readdir_r and localtime_r causes
segmention faults, this is a printout from gdb.

#0  0x4004c93c in __pthread_mutex_lock () at mutex.c:135
#1  0x4004e28c in __fresetlockfiles () at lockfile.c:87
#2  0x400a7053 in _IO_fread (buf=0xbffff7a0, size=44, count=1,
fp=0x804e250)
    at iofread.c:44
#3  0x400c546e in __tzfile_compute (timer=1074773704,
    use_localtime=1074807804, leap_correct=0xbffff860,
leap_hit=0xbffff8cc)
    at tzfile.c:283
#4  0x400c4413 in tzset_internal () at tzset.c:197
#5  0x400c518c in __tz_convert () at tzset.c:561
#6  0x400c1c2f in localtime (t=0xbffff8cc) at localtime.c:49
#7  0x8048f1c in ThreadClass::Notify () at ThreadClass.cc:103
#8  0x8048e48 in ThreadClass::ScanDir (this=0x804c1d0) at
ThreadClass.cc:66
#9  0x8048daa in ThreadClass::Listen (this=0x804c1d0) at
ThreadClass.cc:44
#10 0x8048bfe in main () at main.cc:23

I do'nt know, but I suspect that we might start the thread in an illegal
way

pthread_t
ThreadClass::Run()
{
  pthread_attr_init(&myThreadAttr);
  pthread_attr_setscope(&myThreadAttr, PTHREAD_SCOPE_SYSTEM);

  if (pthread_create(&myThread, &myThreadAttr, SpawnThread, this)==0)
    {
      return myThread;
    }else
      return (0);
}

// this one is declared as static void* in ThreadClass.hh
//  ThreadClass::Listen is a ordinary member function returning void*

void*
ThreadClass::SpawnThread(void* arg)
{
  return (((ThreadClass *) arg)->Listen());
}

Listen memberfunction just sleeps for a while and then it calls ScanDir
that does a readdir_r on a directory, when a file is found it calls
Notify with the filename

void
ThreadClass::Notify(char* filename)
{
  struct stat sbuf;
  struct tm   tptr;

  if (!lstat(filename, &sbuf))
    {
      localtime_r(&(sbuf.st_mtime), &tptr);
    }
}

In localtime_r, the program causes a segm. fault

We have installed
gcc version egcs-2.90.27 980315 (egcs-1.0.2 release)
and the prerequisits that the rpm asked for.

We will be very grateful for any help or suggestions, and, once again,
I'm sorry if  this question doesn't belong here, but after browsing
through this mail archive and searching the net, it seemed to be a good
place to start.

Thorbjörn Eriksson
pt96ter@student.hk-r.se
pt96ter@palantir.proj.ide.hk-r.se


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1998-04-25 16:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <Pine.LNX.3.96.980422125036.3537A-100000@earth.terran.org>
1998-04-22 20:43 ` multithread with egcs/(C++) and RedHat 5.0 Torbjörn Eriksson
1998-04-22 15:21 Kaz Kylheku
1998-04-22 20:43 ` Torbjörn Eriksson
1998-04-23 23:23 ` Niku Kaitaniemi
1998-04-24 11:56   ` Jeffrey A Law
1998-04-25  7:14     ` Michael Alan Dorman
1998-04-25 16:18       ` Jeffrey A Law
  -- strict thread matches above, loose matches on Subject: below --
1998-04-22  8:31 Torbjörn Eriksson

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).