Problem with pthread_join

Discussion in 'C++' started by Damon, Jan 29, 2004.

  1. Damon

    Damon Guest

    Hi,

    I have modified a class and tried to compile but I keep getting
    errors. Can someone advise me what I'm doing wrong here? Thanks alot.

    -----------------error message--------------
    g++ -g -Wall -O -finline-functions -I. -I../lib -c -o eve.o eve.cc
    In file included from realms/world.h:9,
    from eve.cc:8:
    .../lib/my_thread.h: In member function `int mylib::my_thread::Stop()':
    .../lib/my_thread.h:54: invalid conversion from `pthread_t*' to `long
    unsigned
    int'
    make: *** [eve.o] Error 1


    -----------------my_thread.h----------------------
    #ifndef MY_THREAD_H
    #define MY_THREAD_H

    #include "pthread.h"
    #include <iostream>
    /*
    * This code was contributed by Ryan Teixeira ()
    * Thanks for making this code available, dude!
    * Some modifications made by me, of course.
    */

    namespace mylib {
    class my_thread
    {
    private:
    pthread_t ThreadId_;
    void * Arg_;

    protected:
    my_thread() {}

    int Run(void * arg) {
    Setup();
    Execute( arg );
    return 0;
    }

    static void * EntryPoint(void* pthis) {
    my_thread * pt = (my_thread*)pthis;
    pt->Run( pt->Arg() );
    return (void*)NULL;
    }

    virtual void Setup() {}

    virtual void Execute(void* obj) {}

    void * Arg() const { return Arg_; }

    void Arg(void* a){ Arg_ = a; }

    public:
    virtual ~my_thread() {}

    int Start(void * arg) {
    Arg(arg); // store user data
    return pthread_create( &ThreadId_,
    NULL,
    my_thread::EntryPoint,
    this );
    }

    int Stop() {
    return pthread_join( &ThreadId_, NULL ); //problem line
    here.
    }

    };

    };

    #endif
    Damon, Jan 29, 2004
    #1
    1. Advertising

  2. Damon wrote in news::

    > Hi,
    >
    > I have modified a class and tried to compile but I keep getting
    > errors. Can someone advise me what I'm doing wrong here? Thanks alot.
    >


    pthread is outside the topicality of this newsgroup, if you want
    advice on using pthread's you should ask in a threading, unix or
    maybe a gcc newsgroup.

    [snip]

    > namespace mylib {
    > class my_thread
    > {
    > private:
    > pthread_t ThreadId_;
    > void * Arg_;

    [snip]
    >
    > int Stop() {
    > return pthread_join( &ThreadId_, NULL ); //problem line
    > here.


    This is what I found when I put "pthread_join" into google (1st hit):

    int pthread_join(pthread_t thread, void **value_ptr);

    This sugests to me that you should be passing ThreadId_ *not*
    &ThreadId_.

    HTH.

    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
    Rob Williscroft, Jan 29, 2004
    #2
    1. Advertising

  3. Damon wrote:

    > Hi,
    >
    > I have modified a class and tried to compile but I keep getting
    > errors. Can someone advise me what I'm doing wrong here? Thanks alot.
    >
    > -----------------error message--------------


    May I suggest adding -pedantic to make g++ more standard conforming.
    > g++ -g -Wall -O -finline-functions -I. -I../lib -c -o eve.o eve.cc
    > In file included from realms/world.h:9,
    > from eve.cc:8:
    > ../lib/my_thread.h: In member function `int mylib::my_thread::Stop()':
    > ../lib/my_thread.h:54: invalid conversion from `pthread_t*' to `long
    > unsigned
    > int'
    > make: *** [eve.o] Error 1
    >
    >
    > -----------------my_thread.h----------------------
    > #ifndef MY_THREAD_H
    > #define MY_THREAD_H
    >
    > #include "pthread.h"


    Incase you hadn't noticed <iostream> isn't used.
    > #include <iostream>
    > /*
    > * This code was contributed by Ryan Teixeira ()
    > * Thanks for making this code available, dude!
    > * Some modifications made by me, of course.
    > */
    >
    > namespace mylib {
    > class my_thread
    > {
    > private:
    > pthread_t ThreadId_;
    > void * Arg_;
    >
    > protected:
    > my_thread() {}
    >
    > int Run(void * arg) {
    > Setup();
    > Execute( arg );
    > return 0;
    > }
    >
    > static void * EntryPoint(void* pthis) {
    > my_thread * pt = (my_thread*)pthis;
    > pt->Run( pt->Arg() );
    > return (void*)NULL;
    > }
    >
    > virtual void Setup() {}
    >
    > virtual void Execute(void* obj) {}

    If this is an abstract base class you could make it a pure virtual method.
    virtual void Execute(void* obj) = 0;

    >
    > void * Arg() const { return Arg_; }
    >
    > void Arg(void* a){ Arg_ = a; }
    >
    > public:
    > virtual ~my_thread() {}
    >
    > int Start(void * arg) {
    > Arg(arg); // store user data
    > return pthread_create( &ThreadId_,
    > NULL,
    > my_thread::EntryPoint,
    > this );
    > }
    >
    > int Stop() {

    I typed "man pthread_join" and got:
    .....
    int pthread_join(pthread_t th, void **thread_return);
    .....
    hence
    return pthread_join( ThreadId_, NULL ); //problem line

    > return pthread_join( &ThreadId_, NULL ); //problem line
    > here.
    > }
    >
    > };
    >
    > };

    No semi-colon here (after namespace) and I wish all compilers would flag
    it as an error.

    >
    > #endif


    Michael Mellor
    Michael Mellor, Jan 29, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Suurkuusk
    Replies:
    0
    Views:
    3,942
    Andreas Suurkuusk
    Jul 27, 2003
  2. Ted Miller
    Replies:
    0
    Views:
    5,133
    Ted Miller
    Sep 13, 2003
  3. Merek
    Replies:
    0
    Views:
    1,937
    Merek
    Dec 3, 2003
  4. Scott Meddows
    Replies:
    1
    Views:
    375
    John Saunders
    Jun 8, 2004
  5. Mike

    Problem problem problem :( Need Help

    Mike, May 7, 2004, in forum: ASP General
    Replies:
    2
    Views:
    521
    Bullschmidt
    May 11, 2004
Loading...

Share This Page