Results 1 to 2 of 2

Thread: is it legal to declare a pthread_t variable as local?

  1. #1
    Join Date
    Jul 2006
    Posts
    79
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default is it legal to declare a pthread_t variable as local?

    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...
    nass

  2. #2
    Join Date
    Jul 2006
    Posts
    79
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: is it legal to declare a pthread_t variable as local?

    hmmm loooks like i got half my answer.

    Qt Code:
    1. class LogBase
    2. {
    3. ...
    4. void logUpdate(); //this runs and if condition is met a thread is created and runs the AsyncWriteLine() function
    5. void *AsynchWriteLine(void *pThrdStruct); //a fileIO function that is to run as separate thread
    6. }
    To copy to clipboard, switch view to plain text mode 

    and the implelentation
    Qt Code:
    1. void LogBase::logUpdate()
    2. {
    3. FileTime CurTime;
    4. CurTime=GetTime(); //get the Time from epoch
    5. if (CurTime>=Period+PrWriteTime)
    6. {
    7. memcpy(pThrdArg,SensSt,sizeof(ThreadPass)); // struct ThreadPass *pThrdArg;
    8. // is the struct of args for the thread
    9. pthread_t thrdWrt;
    10. pthread_create(&thrdWrt,NULL,AsynchWriteLine,(void *)pThrdArg); //this lines doesn't compile
    11.  
    12. PrWriteTime=CurTime;
    13. }
    14. }
    15.  
    16. void *LogBase::AsynchWriteLine(void *pThrdStruct)
    17. {
    18. ThreadPass * pThrdData = (struct ThreadPass *) pThrdStruct;
    19. ....
    20. ....
    21. }
    To copy to clipboard, switch view to plain text mode 


    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?
    nass
    Last edited by nass; 14th February 2007 at 15:00.

Similar Threads

  1. how to declare a friend variable ?
    By probine in forum General Programming
    Replies: 5
    Last Post: 27th March 2006, 16:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.