Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What do I do if no thread is available to run on a context switch (i.e. all threads are blocked)?

0
Posted

What do I do if no thread is available to run on a context switch (i.e. all threads are blocked)?

0

This situation could arise if all the threads in the system are blocked on semaphores or waiting for alarms. The clock interrupt mechanism we have given you assumes that there is always a thread running, ready to take the interrupt. This means that you have to create an “idle thread”, which is ready to run if all the other threads are blocked, but does nothing (i.e. runs a function which loops infinitely, or yields infinitely). The idle thread should only run if all other threads are blocked, so it should not go on run queue with all the normal threads, and should never block!

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123