Http://www.bkjia.com/kf/201110/107760.html.
You can use C # To specify the CPU on which the current thread runs.
Pass
System. Diagnostics. Process p = Process. GetCurrentProcess ();
P. ProcessorAffinity = (IntPtr) 0x0001;
Process. ProcessorAffinity: sets the shielding word for the current CPU. 0x0001 indicates that CPU 1 is selected, and 0x0002 indicates that CPU 2 is used.
The Code is as follows:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Diagnostics;
Namespace cpu_4_2_csharp
{
Class Program
{
Static void Main (string [] args)
{
System. Diagnostics. Process p = Process. GetCurrentProcess ();
P. ProcessorAffinity = (IntPtr) 0x0001;
Const int SAMPLING_COUNT = 200;
Const double PI = 3.14159;
Const int total_amplece = 250; // the length of each time piece
// Const int system_busy = 10; // take the system cpu consume into consideration
Double [] busySpan = new double [SAMPLING_COUNT];
Int amplitude = (TOTAL_AMPLITUDE)/2;
Double radian = 0.0;
Double radianIncreament = 2.0/(double) SAMPLING_COUNT;
For (int I = 0; I <SAMPLING_COUNT; I ++)
{
BusySpan [I] = (double) (amplitude + Math. Sin (PI * radian) * amplian );
Radian + = radianIncreament;
}
Int startTick = Environment. TickCount;
For (int j = 0; j = (j + 1) % SAMPLING_COUNT)
{
StartTick = Environment. TickCount;
While (Environment. TickCount-startTick) <busySpan [j])
{
//
}
System. Threading. Thread. Sleep (total_ampl--(int) busySpan [j]);
}
}
}
}
Program running result
You can adjust the parameters to make the curve more round, but after debugging for a long time, I got the above. However, the curve graph is much better than the curve graph in http://www.bkjia.com/kf/201110/107760.html.
From: Watkins. Song