类中的p线程函数。假设我有一个类似的类class c {
// ...
void *print(void *){ cout << "Hello"; }}然后我有一个c的向量vector<c> classes; pthread_t t1;classes.push_back(c());classes.push_back(c());现在,我想在c.print();以下是我的问题:pthread_create(&t1, NULL, &c[0].print, NULL);错误输出:无法转换‘void*(tree_tem:)(无效)“to”无效*()(无效)‘for参数’3‘to’int pline_create(p线程_t*,const p线程_attr_t*,void*()(无效),无效*‘
3 回答
临摹微笑
TA贡献1982条经验 获得超2个赞
thispthread_create()thisthis
class C{public:
void *hello(void)
{
std::cout << "Hello, world!" << std::endl;
return 0;
}
static void *hello_helper(void *context)
{
return ((C *)context)->hello();
}};...C c;pthread_t t;pthread_create(&t, NULL, &C::hello_helper, &c);
至尊宝的传说
TA贡献1789条经验 获得超10个赞
class MyThreadClass{public:
MyThreadClass() {/* empty */}
virtual ~MyThreadClass() {/* empty */}
/** Returns true if the thread was successfully started, false if there was an error starting the thread */
bool StartInternalThread()
{
return (pthread_create(&_thread, NULL, InternalThreadEntryFunc, this) == 0);
}
/** Will not return until the internal thread has exited. */
void WaitForInternalThreadToExit()
{
(void) pthread_join(_thread, NULL);
}protected:
/** Implement this method in your subclass with the code you want your thread to run. */
virtual void InternalThreadEntry() = 0;private:
static void * InternalThreadEntryFunc(void * This) {((MyThreadClass *)This)->InternalThreadEntry(); return NULL;}
pthread_t _thread;};
12345678_0001
TA贡献1802条经验 获得超5个赞
pthread_create
cpthread_createc.
static void* execute_print(void* ctx) {
c* cptr = (c*)ctx;
cptr->print();
return NULL;}void func() {
...
pthread_create(&t1, NULL, execute_print, &c[0]);
...}- 3 回答
- 0 关注
- 625 浏览
添加回答
举报
0/150
提交
取消
