Search code examples
c++multithreadingposix

error: ‘pthread’ does not name a type


i am trying compiling my project but seeing the following error.

code : RESTServer.h

#ifndef __RESTSERVER__
#define __RESTSERVER__

#include <string>
#include <pthread.h>

using namespace std;

class RESTServer{
    private:
            RESTServer();
            ~RESTServer();
    public:
            static pthread *thread;
            static void init_rest_server();
};
#endif

Error :

RESTServer.h:14:10: error: ‘pthread’ does not name a type
   static pthread *thread;

I am trying to declare a pointer to pthread as a member of C++ class. Can anyone pls help me here.


Solution

  • Read pthread_create(3); the opaque type is pthread_t (not pthread*) for thread handle.

    BTW, hoping that you use some good C++11 -or C++14- implementation (e.g. GCC 5 or GCC 6 on Linux) you should consider using C++11 threads library, i.e. std::thread.