Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble understanding preemptive kernel

how does preemptive kernel lead to race conditions? if a process is preempted i.e. isn't kicked out of its critical section . from my understanding race condition is when several processes try to access and manipulate resources concurrently right. I have trouble grasping the concept

like image 921
EI-01 Avatar asked Oct 02 '22 03:10

EI-01


1 Answers

A preemptive kernel can start and stop threads at any point. This means that threads that don't carefully coordinate their accesses through locks and critical sections end up in race conditions.

The other form of multithreading is cooperative multithreading, where threads can be stopped only at points where they explicitly offer to yield the processor. This helps prevent race conditions because threads are not interrupted at random unexpected points in their processing.

The downside of cooperative multithreading is that a thread written not to yield can hog the processor, and this is why most modern operating systems use preemptive multithreading rather than cooperative multithreading.

like image 86
Warren Dew Avatar answered Oct 05 '22 13:10

Warren Dew