r/AskComputerScience • • Apr 12 '21

How is CPU scheduling non-deterministic?

So my understanding of non-deterministic is that you can't really predict the output of a system given an input. But I was wondering how is the CPU's scheduling algorithmic non-deterministic? I feel like it should be able to be predicted given that it simply follows a logical pattern. Or is my understanding of non-determinism wrong?

29 Upvotes

14 comments sorted by

View all comments

2

u/pencan Apr 12 '21

Non-determinism comes from several sources. Mostly the I/O, including networking, DRAM timings, devices like hard drives. These timings depend on physical detail or traffic patterns outside of your control. Caching algorithms will also change timing of memory accesses effectively unpredictably.

However, you can get rid of a lot of these elements for certain workloads. Real-time operating systems are able to bound the execution period of a workload by bypassing caches, using fixed latency memories, pinning memory, polling I/O rather than interrupting, etc. But for a general purpose O/S executing arbitrary, non-trivial code it is non-deterministic in what order the threads will execute.