How to use this with C++ code?
Closed this issue · 3 comments
I was trying to figure out how to use this threadpool for my C++ program? Mainly compiling and linking it. I see that there is an 'extern C' for if we have C++ code, but wondering how to use it? Currently these are the errors I get when trying:
thpool.c:86:12: error: declaration of ‘jobqueue thpool_::jobqueue’ [-fpermissive]
jobqueue jobqueue; /* job queue /
^
thpool.c:68:3: error: changes meaning of ‘jobqueue’ from ‘typedef struct jobqueue jobqueue’ [-fpermissive]
} jobqueue;
^
thpool.c: In function ‘int thread_init(thpool_, thread**, int)’:
thpool.c:293:76: error: invalid conversion from ‘void*’ to ‘void* ()(void)’ [-fpermissive]
pthread_create(&(thread_p)->pthread, NULL, (void )thread_do, (thread_p));
^
In file included from thpool.c:16:0:
/usr/include/pthread.h:244:12: note: initializing argument 3 of ‘int pthread_create(pthread_t, const pthr ead_attr_t, void ()(void), void*)’
extern int pthread_create (pthread_t *__restrict __newthread,
I'm trying to compile/link like this:
g++ -std=c++11 main.cpp thpool.c -o main -lssh -pthread
But it doesn't work. How would I make this work?
Unfortunately I have never used C++ so I can't give you any help. I am aware that some people have used the module with C++ without a problem. Hopefully someone will be able to give some feedback on that.
Maybe you can typedef a function pointer like this:
typedef void (*proc)(void*);
void task1(){
err("Thread #%u working on task1\n", (int)pthread_self());
}
thpool_add_work(tpool, (proc)task1, NULL);
Above code compiled success with c++ in my workspace.
Wish to help you.
I close this since someone seems to offered some help.