What is busy waiting with respect to a critical section problem? Can busy waiting be avoided?
Question:
What is busy waiting with respect to a
critical section problem? Can busy waiting be avoided?
Answer:
Waiting is the act of suspending the current thread of execution until
some future event which might be the availability of a contested resource, the
passage of time, or the release of a lock.
Busy waiting means a process is waiting for an event to occur and it does
so by executing instructions. Systems implement busy waiting by simply spinning
in a tight loop, constantly checking if the event in question has occurred.
Busy waiting wastes CPU cycles since nothing useful is done during looping.
Alternative to busy waiting is sleeping. There needs to be built a list
of threads who wish to wait, called a wait queue. The kernel is asked to wake
up a process from the list whenever the event in question happens. For example,
the kernel might be asked to wake up a thread when a specific mutex becomes
available. You then yield to the kernel, allowing it to schedule something else
instead of you.
The benefit of sleeping over busy looping is that the kernel can run
something useful instead for the duration of the wait. The downside is the
overhead: Managing the list, putting the thread to sleep, and context switching
into a new process.
******************
Related Questions:
- What is busy waiting with respect to a critical section problem? Can busy waiting be avoided?
No comments:
Post a Comment