多线程

来源:互联网 发布:淘宝电器以旧换新 编辑:程序博客网 时间:2024/05/16 11:38

多线程:


#include<stdio.h>#include<stdlib.h>#include<windows.h>//创建线程 _beginthread()   CreateThread().//内部结束线程:_endthread()  ExitThread()、外部结束线程 TerminateThread()//冻结线程:SuspendThread(hd); 解冻线程 ResumeThread(hd);DWORD WINAPI fun(void *p){int i = 1;while (i){printf("%d\n", i++);if (i > 80000){//_endthread();//用于线程内部退出ExitThread(0);//结束线程,线程内部}}return 0;}//主线程,主导作用,管理调用共他线程void main(){//创建线程HANDLE hd = CreateThread(NULL, 0, fun, NULL, 0, NULL);system("pause");SuspendThread(hd);//冻结线程system("pause");ResumeThread(hd);//解冻线程TerminateThread(hd,0);//0:代表编号,外部强行结束线程system("pause");}


0 0
原创粉丝点击