⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threadsynchr1.cpp

📁 MFC程序开发参考大全 【明日科技】宋坤 刘锐宁 李伟明 【丛 书 名】 软件工程师典藏 【出 版 社】 人民邮电出版社 本书详细介绍了MFC框架中所有常用类及控件的应用
💻 CPP
字号:
// ThreadSynchr1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "windows.h"


int WorkerID = 10;
const int MAXWORKERID = 100;

//Define thread function
DWORD __stdcall ThreadFunOne(LPVOID lParam)
{
	for(;;)
	{
		if (WorkerID<MAXWORKERID)
		{

			WorkerID +=1;
			Sleep(1000);
			printf("ThreadOne print out: %i \n",WorkerID);
		}
	}
	return 0;
}

DWORD __stdcall ThreadFunTwo(LPVOID lParam)
{
	for(;;)
	{
		if (WorkerID<MAXWORKERID)
		{
			WorkerID +=1;
			printf("ThreadTwo print out: %i \n",WorkerID);
			Sleep(1000);
		}
	}
	return 0;
}

void main()
{
	//Define thread handle
	HANDLE hThread1,hThread2;
	//Create thread
	hThread1 = ::CreateThread(NULL,0,ThreadFunOne,NULL,0,NULL);
	hThread2 = ::CreateThread(NULL,0,ThreadFunTwo,NULL,0,NULL);
	//Close thread handle
	CloseHandle(hThread1);
	CloseHandle(hThread2);
	//Note: Prevent process exiting
	while (true)
	{
		;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -