小编Jac*_*ing的帖子

将字符串传递给pthread函数

我是pthreads的初学者,所以请耐心等待.我正在尝试将字符串传递给thread_routine1函数.它将void指针作为参数.然后我想把它打印出来.

void *thread_routine1(void *arg1){
    cout << arg1 << endl;
    pthread_exit(NULL);
}

int main ()
{
    pthread_t thread1;
    string t1 = "hello", t2 = "world";
    pthread_create(&thread1, NULL,thread_routine1, (void *) t1);
    pthread_join(thread1, NULL);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在pthread_creat函数中我试图传递字符串但是我从字符串到void指针获得了无效的强制转换类型.我知道我可能在不止一个地方出错了所以我会很感激一些指示.

c++ pthreads

4
推荐指数
1
解决办法
391
查看次数

标签 统计

c++ ×1

pthreads ×1