C++ 生成线程

标签 c++ multithreading posix

您好,我需要帮助正确生成线程,我似乎无法正确获取语法。 这是我的代码...

// Spawn a thread--------------------------------------------------#    
    pthread_t thread1;  // thread object
    int rc1;

    if( (rc1=pthread_create( &thread1, NULL, spellCheck, NULL)) )
    {
        cout << "Thread creation failed: " << rc1 << endl;
    }

    pthread_join( thread1, NULL);

函数定义

void spellCheck(vector<string> * fileRead, list<string> * incorrectWord, vector<string> * correctWord)
{   

头文件

void spellCheck(vector<string> *fileRead, list<string> *incorrectWord, vector<string> *correctWord);

任何帮助将不胜感激:)

我的错误:

server.cpp:142: error: invalid conversion from 'void ()(std::vector<std:................. initializing argument 3 of 'int pthread_create(pthread_t, const pthread_attr_t*, void* ()(void), void*)'

最佳答案

我在这里可能是错的,但我认为您实现并传递给 pthread_create() 的线程函数只能有一个 (void*) 输入参数

关于C++ 生成线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10870260/

相关文章:

c++ - 获取尾随 1 位的数量

Java固定线程池每个线程都有资源?

Java在线程中更改字符串值

c - POSIX 正则表达式未编译

windows - 是否可以为 Windows (Win32) 编写 libPOSIX,而不需要始终加载的后台服务或 DLL?

c++ - 自动推断模板中的函数类型

c++ - 如何向可变类声明模板友元函数

java - 共享变量的旧值

检查无线AP是否连接

c++ - NoDecodeDelegateForThisImageFormat 使用 ImageMagick 读取 .png 文件时出错