admin 管理员组

文章数量: 1184232


2024年3月13日发(作者:做小程序开发公司)

Windows多线程编程-C语言

先上代码:

#include

#include // for HANDLE

#include // for _beginthread()

#include

unsigned __stdcall thread(void * i) //子线程入口函数

{

int * k = (int *)i;

printf("这是子线程%dn", *k);

return 1; // the thread exit code

}

int main()

{

HANDLE hth1; //子线程句柄

unsigned Thread1ID; //子线程ID

int i = 1; //子线程入口函数参数

//创建子线程

hth1 = (HANDLE)_beginthreadex(NULL, // security,安全属性

0, // stack size

thread, //子线程入口函数

&i, // arg list 入口函数参数地址

CREATE_SUSPENDED, //先挂起该线程

&Thread1ID); //线程标识符

if (hth1 == 0) //如果返回的hth1的值为0 则表示创建子线程失败

printf("Failed to create thread 1n");


本文标签: 线程 入口 表示