public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* multithread with egcs/(C++) in RedHat 5.0
@ 1998-04-22 15:21 Torbjörn Eriksson
  0 siblings, 0 replies; only message in thread
From: Torbjörn Eriksson @ 1998-04-22 15:21 UTC (permalink / raw)
  To: egcs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2738 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] only message in thread

only message in thread, other threads:[~1998-04-22 15:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-22 15:21 multithread with egcs/(C++) in RedHat 5.0 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).