user3818252
user3818252

Reputation:

Busy waiting and context switch

If I have two processes, why busy waiting avoids the context switch ? And why context switch is less expensive than wasting CPU time in this scenario ? What changes if there are threads instead of processes ?

Thanks!

Upvotes: 1

Views: 1455

Answers (1)

Tony Tannous
Tony Tannous

Reputation: 14856

why busy waiting avoids the context switch

Busy waiting doesn't avoid context switch! context switch is the process in which the scheduler decides to give the CPU to other process to run. Busy waiting is a technique used to keep a process looping and waiting for something. i.e. to prevent two processes from modifying some shared data at the same time. One process will loop until the other process "tell" him it has finished. This is a bad synchronization method as CPU utilization drops as process spends its time burst doing nothing.

And why context switch is less expensive than wasting CPU time

DEPENDS! if the code in critical section is short, busy waiting might be faster than a context switch. A process can ignore signals and by this way run on CPU until it gives it away voluntarily. NOTE not all signals can be ignored.

What changes if there are threads instead of processes ?

I am afraid this is too board to answer as this might depend on OS and if OS is aware of threads.

Upvotes: 2

Related Questions