I will be writing an interface in C++ that controls a large CNC machine and it will run on Windows. For safety reasons, I would like this process to run on it's own core so that it can run the process in real-time. If it shares a core with Windows, all of the Windows processes will be dealt with before my process is. Basically, how do I make sure either my process is always in the front of the processing queue, or how do I designate a core to run my process and leave the other core to handle Windows? Also, is there any way of seeing that my programming is run in real-time. AKA, this core is processing this program, but that core is not doing anything because we told out program not to run on it. Any input would be helpful.
3 Answers
There is no guarantee your process will be dealt with in real time. Windows does not do that. Since you mention safety, I will mention that if a lawsuit occurred you would be in deep trouble. Expert witnesses would testify that the design is inherently unsafe.
User control and display can be done in Windows but real time operations belong in dedicated hardware such as a PLC.

- 10,337
- 2
- 15
- 15
-
This may be a dumb question, but why can't I just run a RTOS on my Windows machine which deals with real-time operations? From my understanding this is becoming somewhat of a standard practice in the industry. User control and display is done by Windows, then the RTOS running on Windows deals with the real-time operations. – TheBlindSpring Jan 28 '14 at 21:27
-
1@TheBlindSpring You can. Although it typically goes the other way - the RTOS runs Windows as one of its tasks. – Eric Brown Jan 28 '14 at 21:39
-
Thank you very much, I am very new to this concept. Do you happen to know where I can learn about this. Like tutorials with maybe some very basic demonstrations showing how to use an RTOS, mainly how to see and make sure the process you want is being processed in real-time, or how to go about running Windows as one of the tasks? – TheBlindSpring Jan 28 '14 at 22:10
-
@TheBlindSpring - a web search for 'Windows RTOS' brings up several candidates, including [Kuka RTOS](http://www.kuka-rtos.com/en/products/vmfwin/), [InTime](http://www.tenasys.com/products/intime.php), and [Wind River](http://rtos.com/products/threadx/Wind_River1702). I'm sure there are more, but it's getting increasingly off-topic. – Eric Brown Jan 29 '14 at 17:24
You can use SetThreadAffinityMask
to restrict a thread to running on some subset of available processors/cores.
If you use SetThreadPriority
and SetProcessPriorityClass
to set a thread to real time priority, only other threads running at real time priority can interrupt it, effectively forcing other threads to run on other cores (unless you raise two or more threads to real time priority.

- 476,176
- 80
- 629
- 1,111
-
1How many Windows threads are running at real-time priority that can interrupt my process? Basically, what are the odds of my thread being interrupted? Is it possible to explicitly say you want thread 'x' to run on core 'y'? Or must I trust Windows to delegate the threads to each core? – TheBlindSpring Jan 28 '14 at 19:02
-
1At real-time priority, the odds of your thread being interrupted are essentially zero. The only exception I know of is if a hardware error triggers a non-maskable interrupt. In the days of single-core machines real-time priority could cause real problems, because it prevented *anything* else from happening, so if you ran that way very long, interrupts didn't get serviced, and (for one example) your memory no longer got refreshed (leading very quickly to the machine crashing). – Jerry Coffin Jan 28 '14 at 19:28
-
So there is no guarantee my process will be dealt with in real time? This may be a better way to describe what I am going for. The interfaces to design, diagnose, optimize and setup a motion control application run under Windows, while the resultant control code and the machine interfaces run on its own core or in an real-time operating system within windows. I am not very familiar with real-time operating system, are all processes ran on RTOS processed in real time? I apologize if this only confuses you further. – TheBlindSpring Jan 28 '14 at 19:56
-
1Ultimately, no--Windows is not designed as a real-time system. Most RTOSes (at least the ones I've seen) support a mixture of real-time processes and best-effort processes. – Jerry Coffin Jan 28 '14 at 20:01
As an alternative, Windows Embedded Compact is a realtime priority-based OS that can make soft realtime guarantees (far better than Windows Vista/7). It's costly, but on par with other commercial RTOSes.

- 13,774
- 7
- 30
- 71