View Full Version : is it legal to declare a pthread_t variable as local?

14th February 2007, 13:00
hello everyone
is it legal to declare a pthread_t variable inside a function of a class,
and then execute with it another function of a class?

i mean what comes to mind is that local variables die with the end of a function execution. but then pthreads are independent of that?
so should i move the declaration of the variabled and make it a class variable or no need?

obviously this is my first attempt in thread... so please bare with me. :)

also you need to add -pthread in the g++ when compiling right?
and only on the compilation of the specific class.. or in main too? or in all the classes that include/are included by this class ?

i wonder...

14th February 2007, 13:27
hmmm loooks like i got half my answer.

class LogBase
void logUpdate(); //this runs and if condition is met a thread is created and runs the AsyncWriteLine() function
void *AsynchWriteLine(void *pThrdStruct); //a fileIO function that is to run as separate thread

and the implelentation

void LogBase::logUpdate()
FileTime CurTime;
CurTime=GetTime(); //get the Time from epoch
if (CurTime>=Period+PrWriteTime)
memcpy(pThrdArg,SensSt,sizeof(ThreadPass)); // struct ThreadPass *pThrdArg;
// is the struct of args for the thread
pthread_t thrdWrt;
pthread_create(&thrdWrt,NULL,AsynchWriteLine,(void *)pThrdArg); //this lines doesn't compile


void *LogBase::AsynchWriteLine(void *pThrdStruct)
ThreadPass * pThrdData = (struct ThreadPass *) pThrdStruct;

so if i try to compile i get

logger.cpp: In member function `void LogBase::logUpdate()':
logger.cpp:281: error: argument of type `void*(LogBase:: )(void*)' does not
match `void*(*)(void*)'

any ideas what i have missed?