thread.cpp

来自「监视CPU使用率的历史情况,个位可以下载后测试测试」· C++ 代码 · 共 32 行

CPP
32
字号
//This piece of code has been written in University of Hull by 
//Warren Viant then Head of Department
//in  Department of Computer Science
//Some alteration have been made by me  

#include "thread.h"


HANDLE Thread::start() {
    unsigned threadId=0;
	_hThread = (HANDLE)_beginthreadex(
		NULL,		// no security attributes (child cannot inherited handle)
		1024*1024,	// 1MB stack size
		threadFunc,	// code to run on new thread
		this,		// pointer to host application class
		0,			// run immediately (could create suspended)
		&threadId	// OUT: returns thread ID
	);
	
	return _hThread;
}

void Thread::waitForTermination() {
	// wait for it to stop
	_isRunning = false ;
	WaitForSingleObject(_hThread, INFINITE);
	// close thread handle
	CloseHandle(_hThread);
	_hThread=0;
	
}

⌨️ 快捷键说明

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