I'm looking for Fresh Response to the outdated responses (and contradictions) I found here and elsewhere. I need to use REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_TIME_CRITICAL, on a few threads. The Responses here and elsewhere are similar to the following;
"Caution: if you are asking for true realtime priority, you are going to get it. This is a nuke. The OS will mercilessly prioritize a realtime priority thread, well above even OS-level input processing, disk-cache flushing, and other high-priority time-critical tasks."
AND...
"This may also cause high temperatures on the CPU and even burn out the CPU or motherboard if the cooling system is not designed for prolonged maximum CPU usage."
ASSUMPTION - Yes I can see that on a Dual Core Processor. I have a Ryzen 7 (8 Cores, 16 Threads). The software being developed is designed to test samples on nothing less. Worst Case Senerio, I would think the OS, would function as if it were running on a Quad core (I'm utilizing 4 threads). And as far as the Burn out, AMD has an unlock feature on some of these processors to push overclocking abilities safely. I kind of doubt burn out. BUT I COULD BE WRONG, Please feel free to correct me.
WHY: The software processes Group of samples. Each group must be processed so the results can be passed on to the next group. The Threads are released upon the group and then they can relax, while the next group set.
The software NOW is running strictly on Atomic Variables used as switches. I had one last bottleneck that was requiring 2 Spinlocks/Mutex (Because windows context out the thread in the critical section - or worse). REALTIME_PRIORITY_CLASS would have resolved it, but An Array of Atomic_ints used as Latches/switches resolved that problem of how to handle straggling threads, a little more safely. Examples of Atomic Switches.
if (Worker.fetch_add(1) == 0) //FIRST THREAD IN
DoFirstThreadJob(0);
if (Worker.fetch_sub(1) == 1) // LAST THREAD OUT
DoCleanUpJob(1);
/// QUICK TRY LOCK
if (!OnlyOneAtATime.fetch_add(1))
{
SetupStuff()
}
OnlyOneAtATime.fetch_sub(1);
// MULTI THREAD INDEXER SO EACH THREAD GETS ITS OWN TASK
LocalIndex = AtomicIndexer.fetch_add(1);
while (LocalIndex < GlobalMaxBatchCount)
{
DoBatchAssignment(LocalIndex);
LocalIndex = AtomicIndexer.fetch_add(1);
}
SO THE QUESTION(S) REMAINS;
Our experiment of realtime, kept the threads tight (NOT - 1 or 2 threads, 1..3 levels down from the current batches). If I keep them tight, I can take out a wait loop, and let them start on the next series of test (free flow). The computer ran smoothly on all-out FULL-BLOWN NUKE of 4 threads. BUT 10-15 minute test is not 3 or 4 hours. Will someone wake me in the morning and say a blob of Plastic is sitting where the computer was (I'm trying to stay Amused)?
The following Example Shows one test of Switching Out. If I have to play it safe, how much time am I loosing, switching back and forth? (As mentioned, we had this cranked all the way up, using 4 threads (1/2 the core count) NO SWITCHING OUT, and the computer ran smoothly).
The Threads would go through "Manager" and “Class” Bumped UP to "REALTIME", when they return Class is bumped down. Right before they Process a batch, the Thread Priority would get Bumped UP to "TIME_CRITICAL", then "NORMAL" upon its return.
void DoBatchWork(BatchResultType ResultList)
{
///////////////////////////////////////////////////// START CRITICAL ZONE
if (!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL))
ErrorLog(103, GetLastError());
//////////////////////////////////////////////////////START CRITICAL ZONE
GetResultsOfBatchTest(ResultList);
///////////////////////////////////////////////////// END CRITICAL ZONE
if (!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL))
ErrorLog(104, GetLastError());
//////////////////////////////////////////////////////END CRITICAL ZONE
}
void Manager()
{
if (!SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS))
Log(101, GetLastError());
/////////////////////////////////////////////////////////////////////
WorkOnAllBatches();
/////////////////////////////////////////////////////////////////////
if (!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS))
Log(102, GetLastError());
}
WHAT HAVE I DONE... You can see there are a good 1000+ combinations to try. If SOMEONE here has pushed the limits, please chime in. I could be doing this for several days, when the HIGHEST (APPEARS) to be okay.
SIDE NOTE: I see some response on other questions was to dedicate the cores (affinity). I also see CONTRADICTION on other questions about "how to affinity", that you don't want to do that, Windows manages things such as overheating, etc. IN TRUTH, the CPU (if it does) and the OS can switch the threads to different cores and manage, thread-to-core (Better than I can). I'm okay with that. I'm focused on lengthy "Time sliced threads". SO I'll let windows and the processor to do what it does best.