Creating threads in C vs C++

Discussion in 'C Programming' started by john, Jan 8, 2010.

  1. john

    john Guest

    Hi,

    I'm writing a multithreaded application in C++. I tried to do like C
    posix threads and pass an object method. But I got a compilation error:

    'argument of type 'void*(myclass::)(void *)' does not match 'void *
    (*)(void *)'

    I've done lots of multithreaded work in C. But this my first time doing
    it in C++. How do I create a thread in C++?

    Cheers

    John
     
    john, Jan 8, 2010
    #1
    1. Advertising

  2. john

    Guest

    On Jan 8, 5:36 pm, john <> wrote:
    > Hi,
    >
    > I'm writing a multithreaded application in C++. I tried to do like C
    > posix threads and pass an object method. But I got a compilation error:
    >
    >    'argument of type 'void*(myclass::)(void *)' does not match 'void *
    > (*)(void *)'
    >
    > I've done lots of multithreaded work in C. But this my first time doing
    > it in C++. How do I create a thread in C++?
    >
    > Cheers
    >
    > John


    It looks like your attempting to use a class member function pointer
    where a just a plain function pointer is expected. You will have to
    make the function either a class static function a free function
    (outside of any class).

    HTH
     
    , Jan 8, 2010
    #2
    1. Advertising

  3. john

    Ian Collins Guest

    wrote:
    > On Jan 8, 5:36 pm, john <> wrote:
    >> Hi,
    >>
    >> I'm writing a multithreaded application in C++. I tried to do like C
    >> posix threads and pass an object method. But I got a compilation error:
    >>
    >> 'argument of type 'void*(myclass::)(void *)' does not match 'void *
    >> (*)(void *)'
    >>
    >> I've done lots of multithreaded work in C. But this my first time doing
    >> it in C++. How do I create a thread in C++?
    >>
    >> Cheers
    >>
    >> John

    >
    > It looks like your attempting to use a class member function pointer
    > where a just a plain function pointer is expected. You will have to
    > make the function either a class static function a free function
    > (outside of any class).


    A static member function isn't strictly correct, the thread function
    should be a C linkage (extern "C") free function. This can still be a
    friend of the class.

    --
    Ian Collins
     
    Ian Collins, Jan 8, 2010
    #3
  4. john

    Rui Maciel Guest

    john wrote:

    > Hi,
    >
    > I'm writing a multithreaded application in C++.

    <snip />

    I believe that, for that topic, you will get better answers in a newsgroup
    dedicated to parallel programming, such as comp.programming.threads.

    Other than that, in order to help others help you, it would be better if you
    provided an example of the offending code.


    Rui Maciel
     
    Rui Maciel, Jan 9, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike King

    Creating Threads safe?

    Mike King, Mar 27, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    333
    Eliyahu Goldin
    Mar 27, 2006
  2. yoda
    Replies:
    2
    Views:
    482
    =?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=
    Aug 1, 2005
  3. threads without threads

    , Aug 27, 2004, in forum: C Programming
    Replies:
    4
    Views:
    448
    William Ahern
    Aug 27, 2004
  4. Pedro Pinto

    Java Threads - Get running threads

    Pedro Pinto, Apr 8, 2008, in forum: Java
    Replies:
    2
    Views:
    1,524
    Arne Vajhøj
    Apr 9, 2008
  5. Une bévue
    Replies:
    0
    Views:
    187
    Une bévue
    Jun 14, 2006
Loading...

Share This Page