最近须用c语言编程,需要创建进程或者线程,但是查阅了两种创建线程的方法都报错,是怎么回事?
#include<windows.h>
#include<iostream>
#include <stdio.h>
/* 线程函数声明 */
void Thread1(void*);
void Thread2(void*);
//unsigned int __stdcall Thread1ex(void*);
//unsigned int __stdcall Thread2ex(void*);
/* 线程句柄 */
HANDLE h1, h2;
int main(int argc, const char** argv) {
h1 = (HANDLE)_beginthread(Thread1, 0, NULL);//线程1
h2 = (HANDLE)_beginthread(Thread2, 0, NULL);//线程2
//h1 = (HANDLE)_beginthreadex(NULL, 0, Thread1ex, NULL, 0, NULL);
//h2 = (HANDLE)_beginthreadex(NULL, 0, Thread2ex, NULL, 0, NULL);
WaitForSingleObject(h1, INFINITE);//等待线程1结束
WaitForSingleObject(h2, INFINITE);//等待线程2结束
//system("pause");
printf("主线程结束\n");
return 0;
}
/* 线程1 */
void Thread1(void* arg)
{
while (1)
{
printf("Thread1\n");
Sleep(100);
}
}
/* 线程2 */
void Thread2(void* arg)
{
while (1)
{
printf("Thread2\n");
Sleep(100);
}
}
报了一堆错误,也尝试了createthread,也会报出上面的错误,该怎么解决