cpu 占用百分之五十

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <assert.h>
#include <iostream>
using namespace std;

#define US_PER_MS 1000
#define MS_PER_SEC 1000
#define SPEED 60000000UL

void Thread()

 BOOL b = SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS) ;
 assert(b);
 b = SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
 assert(b);
 DWORD d = SetThreadAffinityMask(GetCurrentThread(), 0x00000002);
 assert(d);
 INT64 try00 = SPEED;
 int ms;
 clock_t s, e;
 while (1)
 {
  s = clock();
  while (try00--);
  e = clock();
  ms = (e - s) * MS_PER_SEC / CLOCKS_PER_SEC;
  Sleep(ms);
  try00 = SPEED;
 }
}

int main(int argc, char **argv)
{
 HANDLE hThread;
 DWORD ThreadID;
 hThread=CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Thread, NULL, 0, &ThreadID);

 if (NULL != ThreadID)
 {
  WaitForSingleObject(hThread, INFINITE);   //用于等待线程1安全结束
 }

 exit(0);
}

 

本人为4核机器,只有第二个cpu显示占用百分之五十,启动4个进程,感觉cpu就很混乱,占用就不规律了。希望大神补充下多核均占用百分之五十的代码。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值