This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: multithread with egcs/(C++) and RedHat 5.0




On Wed, 22 Apr 1998, B. James Phillippe wrote:

> On Wed, 22 Apr 1998, Torbjörn Eriksson 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.
> 
> Hello.  I too am a beginning pthreads programmer.  I'm not sure I can help
> you, but I do have two questions for you.  See below..
> 
> > Our problem is that system calls like readdir_r and localtime_r causes
> > segmention faults, this is a printout from gdb.
> 
> I was under the impression that we should not use explicit _r variants
> (such as localtime_r); instead to compile with -D_REENTRANT would
> automatically use the reentrant versions.

Actually, we use -D_REENTRANT too, 

> 
> >   if (pthread_create(&myThread, &myThreadAttr, SpawnThread, this)==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());
> > }
> 
> This looks like you are trying to initialize a pthread with a pointer to
> member function (being cast to a void*).  I believe this is not allowed,
> because a pointer to member function is actually an offset into an object,
> and not simply the absolute address of a function.  Also, in section 5.6 of
> Stroustrup's 3rd ed. "C++ Programming Language" there is specific statement
> that pointer to function and pointer to member can not be assigned to
> void*.

The Spawnthread function is a memberfunction but it's declared as static
void * in the class ThreadClass. I have also tried to get it to work by
creating a non member function, static void *, that was called by
pthread_create. This function then created the object of type ThreadClass
and run its memberfunction obj->Listen().  

 > 
> Again, I am a threads novice so I may be mistaken.

As I said in my first mail, we appreciate any effort to help us get our
project running ;-)
  
> But that is the
> understanding that I have been programming with, using pthreads and C++ on
> a RedHat 5.0 glibc system.
> 
> Hope this helps,
> -bp
> --
> B. James Phillippe <bryan@terran.org>
> Linux Software Engineer, WGT Inc.
> http://earth.terran.org/~bryan
> 
> 



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]