0

I'm trying to create my own Thread class so that I don't have to operate directly on native functions, but I'm a little bit stuck with pthread_create function, as it doesn't seem to accept a pointer to a method. Is there a way to cast it somehow in a way it works? I currently get an error saying "cannot convert ‘Thread::run’ from type ‘void* (Thread::)(void*)’ to type ‘void* ()(void)’"

class Thread {
    pthread_t handle;

protected:
    bool endThread;

public:

    virtual ~Thread() {

    }

    void start() {
        endThread = false;
        pthread_create(&handle, NULL, Thread::run, NULL);
    }

    void stop() {
        endThread = true;
    }

    void join() {
        pthread_join(handle, NULL);
    }

    virtual void* run(void * param) {

        return NULL;
    }

};
Kamil Janowski
  • 1,872
  • 2
  • 21
  • 43
  • in C++11, you may use `std::thread`. – Jarod42 Jul 27 '14 at 09:22
  • yeah... I know about c++11, but I'm not entirely sure if it's the right solution. I mean, I also need to use semaphores in my project. C++11 doesn't contain semaphores and therefore I have to use the ones provided by posix standard and I'm not 100% sure if it's a legit approach – Kamil Janowski Jul 27 '14 at 09:25
  • Look at [c0x-has-no-semaphores-how-to-synchronize-threads](http://stackoverflow.com/questions/4792449/c0x-has-no-semaphores-how-to-synchronize-threads) to see how to implement semaphore in C++11 – Jarod42 Jul 27 '14 at 09:33

0 Answers0