473,396 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 (ry**@geocities.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
Jul 22 '05 #1
2 2614
Damon wrote in news:15**************************@posting.google.c om:
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/
Jul 22 '05 #2
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 (ry**@geocities.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;

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
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Matthew | last post by:
Hi, I am using sun's CC (c++ compiler) to compile the follow code: #define __REENTRANT #include <stdio.h> #include <pthread.h> void *one(void *dummy);
117
by: Peter Olcott | last post by:
www.halting-problem.com
9
by: nan.li.g | last post by:
Hello, all, I have an interesting problem about stl map and pthread on Linux and g++. The source code is as follows. //mt_map_test.cpp #include <string> #include <map> #include <unistd.h>...
10
by: david wolf | last post by:
The following pthread code cannot compile, I want to know why. Can somebody give me direction on this? if I replace the following line of code status1 = pthread_create(&threadID1, NULL, read,...
2
by: ArmedCoder | last post by:
Hi, im just learning about multithreading for a program i am writin that needs to read from multiple camreas attached to the computer a the same time. I know how to create threads and pass around...
39
by: elnanni | last post by:
I've a problem in the use of threads, they don't work as i want them to. Here's the code, the problem is that if i uncomment the //pthread_join(thread_ID, NULL);, the main program stops until the...
0
by: amitdangwal | last post by:
I have made the following program, but the thread is not running. Output says thread created but the thread function (which i want to call so as to perform the deletion of file from a path) is not...
3
by: bangaw | last post by:
i'm currently using c++ on windowsXP, unistd.h doesnt work for windows what other substitute for it could i use to replace it Pls. Help me Pls pls the code goes as follows #include <stdio.h>...
3
by: mhrt2008 | last post by:
hi all i am using thread to print the value of x i though the value will be 10, but i found it 0????? Why , and haw can i adjust this thread to print x=10 #include <stdio.h> #include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.