栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

网络游戏服务器编程

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

网络游戏服务器编程

多线程编程示例
#include
#include
#include
#include
#define WIN32_LEAN_AND_MEAN

DWORD WINAPI ThreadFunc(LPVOID);

int main()
{
	HANDLE hThred1;
	HANDLE hThred2;
	DWORD  exitCode1 = 0;
	DWORD exitCode2 = 0;
	DWORD threadId;

	hThred1=CreateThread(NULL,0,ThreadFunc,(LPVOID)1,0,&threadId);

	if (hThred1)
	{
		printf("Thread 1 launchedn");

	}

	hThred2 = CreateThread(NULL, 0, ThreadFunc, (LPVOID)2, 0, &threadId);
	if (hThred2)
	{
		printf("Thread 2 launchedn");
	}

	for (;;)
	{
		printf("Press any key to exit..n"); 
		_getch();
		GetExitCodeThread(hThred1, &exitCode1);
		GetExitCodeThread(hThred2, &exitCode2);

		if (exitCode1 == STILL_ACTIVE)
			puts("Thread 1 is still running!");
		if (exitCode2 == STILL_ACTIVE)
			puts("Thread 2 is still running!");
		if (exitCode1 != STILL_ACTIVE && exitCode2 != STILL_ACTIVE)
			break;
	}

	CloseHandle(hThred1);
	CloseHandle(hThred2);

	printf("Thread 1 returned %dn", exitCode1);
	printf("Thread 2 returned %dn", exitCode2);

	return EXIT_SUCCESS;
}

DWORD WINAPI ThreadFunc(LPVOID n)
{
	Sleep((DWORD)n * 1000 * 2);
	return (DWORD)n * 10;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/694356.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号