From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
07-08-2021 11:42 AM
I mean, if that's what you are trying to do, in most cases it shouldn't be necessary at all. If you're not running your thread at the top priority level, Windows will do this automatically after a time in any case, whether you want it to or not.
And unless you're running on an amazingly cheap or old processor, most processors today have multiple cores and so even if you did lock one single thread it wouldn't stop the rest of the system from running.
07-08-2021 12:08 PM - edited 07-08-2021 12:19 PM
@nanocyte wrote:
Can you point to documentation that describes this? Is it Windows specific? My intent was to have a small wait so as not to starve other threads but 2 ms was too long so a 0 ms wait might be just what I'm looking for.
The Help function for Wait (ms) says:
Wiring a value of 0 to this parameter forces the current thread to yield control of the CPU.
07-09-2021 02:30 AM
@nanocyte wrote:
Can you point to documentation that describes this? Is it Windows specific? My intent was to have a small wait so as not to starve other threads but 2 ms was too long so a 0 ms wait might be just what I'm looking for.
https://stackoverflow.com/questions/3727420/significance-of-sleep0
07-09-2021 02:57 AM
Wait (ms) is in the help (CTRL+h or online).
If you just want to avoid 100% CPU without slowing down your loop too much, you can wait every few iterations:
1.5 decade ago I tested reading the CPU load, and using a controller (P or PI) to conditionally wait to get to a setpoint CPU load. It worked, but seemed too complicated to be practical. I never actually used it.