我正在尝试使用 for 循环创建 3 个线程。以下是我的代码片段:
DWORD WINAPI ThreadProc0(LPVOID param)
{
return 0;
}
DWORD WINAPI ThreadProc1(LPVOID param)
{
return 0;
}
DWORD WINAPI ThreadProc2(LPVOID param)
{
return 0;
}
int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
DWORD threadId = 0;
int max_number=1;
//Start the threads
typedef DWORD (WINAPI * THREADPROCFN)(LPVOID lpParameter);
THREADPROCFN function[3] = {ThreadProc0,ThreadProc1,ThreadProc2} ;
for (int i = 0; i < max_number; i++)
{
CreateThread( NULL,
0,
(LPTHREAD_START_ROUTINE)&function[i],
(LPVOID) i,
0,
NULL
);
}
}
代码编译成功,但执行时,错误是solution.exe已停止工作。当我调试代码时,我收到以下错误:
Solution.exe 中 0x0034fd00 处的未处理异常:0xC0000005:访问冲突。
等待帮助。