What makes the execution order of threads unpredictable?

advertisements

What makes the execution order of threads unpredictable? Does the scheduler at some point use random numbers or check system resources or see which thread has waited long enough or ...?


The scheduler is, usually, the OS's scheduler. It is influenced by many factors, including what other processes on the machine are doing, what the hardware is doing (interrupts), etc. Depending on the OS, I suppose there may sometimes be random numbers involved, but I suspect generally not. It's more just the unpredictable way that multiple variable time intervals can overlap.