views:

41

answers:

2

In a OS we originally have a ready-queue for the threads, note only one queue. Why would it be better to have different queues for each semaphore. Pros and cons can be about efficiency, complexity or something else.

+1  A: 

I am going to assume that you have a uniprocessor system (having multiple processors may potentially impact the number of ready queues).

What is in your ready queue? Most ready queue's I have seen contain a list of all the threads that are ready to run. This of course is different than all the threads in the system. If this model matches your setup, I would recommend sticking with a single ready queue. When it comes to scheduling or picking the next thread to run, you only have to check one queue and you don't have to worry about suspended tasks in that queue.

It may also be worthwhile to have one pend queue per semaphore. The pend queue will keep track of all the threads that are waiting on the semaphore. As the thread is waiting, it is not ready, and not in the ready queue.

Doing it this way helps keep threads in similar states together. Consequently, when you have to search through these lists, you can keep the overhead to a minimum.

Hope this helps.

Sparky
The ready queue contains all threads that are ready to run so in my case all threads should have been in that queue. Thanks for your help.
Joelmob
+2  A: 
tommieb75
Nicely done! The OS we had at our lab session used an array which contained all thread info and stack pointers, having a linked list would be more efficient in moving/removing tasks and i guess most systems do but our toy OS was just for understanding the basics.
Joelmob