使用_beginthread创建线程

一个简单的使用_beginthread创建线程的例子。所在头文件为process.h。

_beginthead的函数原型为:_beginthread(void(_cdecl *start_address) (void*), unsigned stack_size, void* arglist);

参数分别为:函数的入口地址,栈大小, 参数列表。

根据函数原型的第一个参数,可知,线程函数的语法如下:

void _cdecl ThreadFunc(void * param){}


//用_beginthread 创建线程
//注:对应的线程函数的语法为
// void _cdecl ThreadProc(void* pParam); 

#include 
#include 
#include 

using namespace std;

void ThreadFun1(PVOID param){
	while (1){
		Sleep(1000);
		cout << "this is ThreadFun1" << endl;
	}
}

void  ThreadFun2(PVOID param){
	while (1){
		Sleep(1000);
		cout << "this is ThreadFun2" << endl;
	}
}

int main(){
	int i = 0;

	_beginthread(ThreadFun1, 0, NULL);
	_beginthread(ThreadFun2, 0, NULL);
	Sleep(30000);
	cout << "end" << endl;
	return 0;
}



你可能感兴趣的:(windows多线程)