简单pthread! C ++ [英] Simple pthread! C++

查看:82
本文介绍了简单pthread! C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么这不工作

I have no idea why this doesn't work

#include <iostream>
#include <pthread.h>
using namespace std;

void *print_message(){

    cout << "Threading\n";
}



int main() {

    pthread_t t1;

    pthread_create(&t1, NULL, &print_message, NULL);
    cout << "Hello";

    return 0;
}

错误:

*),void *)'threading.cpp threading / src line 24 C / C ++
问题

[Description, Resource, Path, Location, Type] initializing argument 3 of 'int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)' threading.cpp threading/src line 24 C/C++ Problem


推荐答案

你应该将线程main声明为:

You should declare the thread main as:

void* print_message(void*) // takes one parameter, unnamed if you aren't using it

这篇关于简单pthread! C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆