 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Damon Guest
|
Posted: Thu Jan 29, 2004 2:37 pm Post subject: Problem with pthread_join |
|
|
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 (ryte (AT) geocities (DOT) com)
* 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
|
|
| Back to top |
|
 |
Rob Williscroft Guest
|
Posted: Thu Jan 29, 2004 3:02 pm Post subject: Re: Problem with pthread_join |
|
|
Damon wrote in news:159c8bc6.0401290637.2f5ad564 (AT) posting (DOT) google.com:
| Quote: | 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]
| Quote: | 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/
|
|
| Back to top |
|
 |
Michael Mellor Guest
|
Posted: Thu Jan 29, 2004 3:03 pm Post subject: Re: Problem with pthread_join |
|
|
Damon wrote:
| Quote: | 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.
| Quote: | 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.
| Quote: | #include <iostream
/*
* This code was contributed by Ryan Teixeira (ryte (AT) geocities (DOT) com)
* 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;
| Quote: |
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
| Quote: | 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.
Michael Mellor
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|