Exforsys
+ Reply to Thread
Results 1 to 2 of 2

pthread.h please help

This is a discussion on pthread.h please help within the Software Patterns forums, part of the Testing category; I am trying to spawn a thread that is a member function: pthread_create(&thread, NULL, (void*)&CLASSNAME::functionname, NULL); I am getting this ...

  1. #1
    sportvette Guest

    pthread.h please help

    I am trying to spawn a thread that is a member function:

    pthread_create(&thread, NULL, (void*)&CLASSNAME::functionname, NULL);

    I am getting this error message:
    converting from 'void (CLASSNAME::*)()' to 'void *'
    ANSI C++ forbids implicit conversion from 'void*' in argument passing

    any help would be appreciated.

    Thanks,
    Mark Fleureton



  2. #2
    Artie Gold Guest

    Re: pthread.h please help

    sportvette wrote:
    > I am trying to spawn a thread that is a member function:


    You can't. At least not directly.
    Member functions and regular functions are different, incompatible
    creatures.
    Member functions operate on an object; where (oh where) is this object
    supposed to come from?

    >
    > pthread_create(&thread, NULL, (void*)&CLASSNAME::functionname, NULL);
    >
    > I am getting this error message:
    > converting from 'void (CLASSNAME::*)()' to 'void *'
    > ANSI C++ forbids implicit conversion from 'void*' in argument passing


    OK. You're trying a cast (one which makes no sense on its face) -- and
    you're even casting to the WRONG TYPE!

    [have you even looked at the prototype for pthread_create()?]

    What you need to do is write a wrapper with "C" linkage to pass to
    pthread_create().

    BTW - WTF are you asking this here? More significantly, this comes up on
    news:comp.programming.threads (where this question would belong if it
    hadn't been asked and answered countless times already) every week or
    so. Have you bothered to look (or lurk) there?

    --ag

    --
    Artie Gold -- Austin, Texas




Latest Article

Network Security Risk Assessment and Measurement

Read More...