使用CreateThread启动线程时出错

时间:2018-03-18 06:13:05

标签: multithreading c++11 winapi console-application createthread

我正在尝试创建一个调度程序,在创建一个线程时,它会出现以下错误:

  

类型的参数" DWORD(*)(LPVOID lpParameter)"与" LPTHREAD_START_ROUTINE"的类型参数不兼容。

我按照其他问题的建议使线程函数静态,但仍然会出现同样的错误。任何解决方案或指针将不胜感激。

这是我的代码的相关部分:

#include "stdafx.h"
#include <string>
#include <windows.h>
#include <vector>
#include <stdio.h>
#include <thread>

using namespace std;

struct process {
    int PID = 0;
    int burstTime;
    int arrivalTime;
    int priority;
};

vector<process> allProcesses;
process myProcess;

vector<HANDLE> handles;
vector<DWORD> dwords;

static DWORD myThread(LPVOID lpParameter)
{
    //execute my thread
}

void newArrival()
{
    DWORD tempThreadID;
    dwords.push_back(tempThreadID);

    ////error happens here at myThread
    handles.push_back(CreateThread(0, 0, myThread, &allProcesses[0], 0, &dwords[dwords.size() - 1]));

    //do even more stuff
}

void scheduler()
{
    //do some other stuff
    newArrival();
    //do more stuff
}

int main()
{
    //do some stuff

    myProcess.arrivalTime = 1000;
    myProcess.burstTime = 2500;
    myProcess.priority = 90;

    allProcesses = {myProcess};

    thread scheduler(scheduler);

    system("PAUSE > null");
    return 0;
}

0 个答案:

没有答案