(本文章旨在个人回顾知识点)
windows系统创建线程:
(当然MFC、QT也有对应创建线程的接口函数)
1、使用windows API CreateThread创建线程:
(不建议使用该接口创建线程)具体原因:http://blog.csdn.net/hkwlg1314/article/details/49429925
2、使用_beginThread创建线程:
①头文件:#include
②函数原型:
_CRTIMP uintptr_t __cdecl _beginthread
(
_In_ void (__cdecl * _StartAddress) (void *), //线程调用的函数的起始地址
_In_ unsigned _StackSize, //新线程的栈大小,0为默认
_In_opt_ void * _ArgList //线程执行函数的参数
);
③返回值为线程句柄
简单列子:
#include
#include
#include
using namespace std;
void threadFun(void* param)
{
cout << "这是子线程!" << endl;
return;
}
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE threadHandle = (HANDLE)_beginthread(threadFun, 0, NULL);
if ((HANDLE)-1 == threadHandle)
{
cout << "创建线程失败!(牛B了你)" << endl;
}
cout << "这是主线程!" << endl;
system("pause");
return 0;
}
下面内容引用:http://blog.csdn.net/stven_king/article/details/50353628