📄 threadsynchr1.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 + -