本帖最后由 Cool_Breeze 于 2021-3-18 10:23 编辑
[Python] 纯文本查看 复制代码 # coding=utf-8
from os import cpu_count
from time import strftime, sleep
from multiprocessing import Process, freeze_support
def full():
number = 0
while True:
if number > 10000:
number = 0
number += 1
def showTime():
while True:
print(f'\r本地时间:{strftime("%Y-%m-%d %H:%M:%S")}', end='', flush=True)
sleep(1)
if __name__ == '__main__':
freeze_support()
kernel = cpu_count()
print(f'CPU 暖手器已开启 {kernel} 个核心')
pro = [Process(target=full, daemon=True) for n in range(kernel)]
for p in pro: p.start()
showTime()
for p in pro: p.join()
[C#] 纯文本查看 复制代码 using System;
using System.Threading;
class Test
{
static void Main()
{
int PoolSize = Environment.ProcessorCount; // 获取当前计算机上的处理器数。
Thread[] ThreadPool = new Thread[PoolSize];
for (sbyte i=0; i<PoolSize; i++)
ThreadPool[i] = new Thread(Occupy);
for (sbyte i=0; i<PoolSize; i++)
ThreadPool[i].Start();
while (true)
{
Console.Write("\r{0}", DateTime.Now);
Thread.Sleep(500);
}
}
static void Occupy()
{
long Total;
sbyte n;
while (true)
{
Total = 0;
for (n=0; n<127; n++)
Total += n;
}
}
}
毒盘链接:https://pan.baidu.com/s/1AJyhxvS-m-lfzQMgtuKIyQ
提取码 |