Efficient mechanism for preventing starvation in counting semaphores
First Claim
Patent Images
1. A computer-implemented method for allocating a plurality of resources to a plurality of threads in a counting semaphore that protects the plurality of resources, said method comprising:
- maintaining a count of how many of the resources the semaphore currently has available for the threads;
putting one of the threads to sleep on a wait queue if the semaphore does not have enough of the protected resources that are available to satisfy the one of the threads;
waking the sleeping thread up from the wait queue if the protected resources become available for the sleeping thread;
allowing other threads to steal the protected resources from the woken thread before the woken thread can execute;
allowing a starving one of the threads to be woken and execute if the starving one of the threads has had more than a predetermined maximum number of the protected resources stolen from it;
allowing other threads to steal resources from the sleeping thread on the wait queue if the sleeping thread needs the plurality of protected resources and the semaphore has fewer of the protected resources available than the sleeping thread needs; and
maintaining a count of the number of the protected resources that are stolen from one of the threads to determine if the thread is starving.
1 Assignment
0 Petitions
Accused Products
Abstract
An algorithm for preventing starving threads in a counting semaphore for a computer operating system. The algorithm operates in a stealing mode where threads can steal resources from other threads if none of the threads is starving, and operates in a first-in first-out mode if one or more of the threads becomes starving.
-
Citations
17 Claims
-
1. A computer-implemented method for allocating a plurality of resources to a plurality of threads in a counting semaphore that protects the plurality of resources, said method comprising:
-
maintaining a count of how many of the resources the semaphore currently has available for the threads; putting one of the threads to sleep on a wait queue if the semaphore does not have enough of the protected resources that are available to satisfy the one of the threads; waking the sleeping thread up from the wait queue if the protected resources become available for the sleeping thread; allowing other threads to steal the protected resources from the woken thread before the woken thread can execute; allowing a starving one of the threads to be woken and execute if the starving one of the threads has had more than a predetermined maximum number of the protected resources stolen from it; allowing other threads to steal resources from the sleeping thread on the wait queue if the sleeping thread needs the plurality of protected resources and the semaphore has fewer of the protected resources available than the sleeping thread needs; and maintaining a count of the number of the protected resources that are stolen from one of the threads to determine if the thread is starving. - View Dependent Claims (2, 3, 4, 5, 6, 7, 8, 9, 10)
-
-
11. A computer-implemented method for allocating a plurality of resources to a plurality of threads in a counting semaphore that protects the plurality of resources, said method comprising:
-
operating in a stealing mode where one of the threads can steal the protected resources from the other threads when none of the threads is starving for any of the protected resources, wherein operating in the stealing mode includes allowing threads to steal the protected resources from a sleeping one of the threads on a wait queue if the sleeping thread needs more than one of the protected resources and the semaphore has less of the protected resources than the sleeping thread needs; operating in a first-in first-out mode when one or more of the threads are starving for any of the protected resources; and maintaining a count of the number of the protected resources that are stolen from one of the threads to determine if the thread is starving. - View Dependent Claims (12, 13, 14)
-
-
15. A computer-implemented method for allocating a plurality of resources to a plurality of threads in a counting semaphore that protects the plurality of resources, said method comprising:
-
maintaining a count of how many of the protected resources the semaphore currently has available for the threads; putting one of the threads to sleep on a wait queue if the semaphore does not have enough of the protected resources available to satisfy the one of the threads; waking the sleeping thread up from the wait queue if the protected resources become available for the sleeping thread; maintaining a count of how many of the protected resources are needed by the ones of the threads that have been woken from the wait queue and are waiting to execute; maintaining a count of how many of the protected resources the sleeping ones of the threads and the woken ones of the threads have attempted to get from the semaphore, but have failed; allowing other ones of the threads to steal the protected resources from a particular woken one of the threads before the particular woken one of the threads can execute; allowing other ones of the threads to steal the protected resources from a particular sleeping one of the threads at a front of the wait queue if the particular sleeping one of the threads needs the protected resources and the semaphore has fewer of the protected resources available than the particular sleeping one of the threads needs; maintaining a count of the number of the protected resources that are stolen from one of the threads to determine if the thread is starving; allowing a starving one of the threads to be woken and execute if the starving one of the threads has had more than a predetermined number of the protected resources stolen from it, wherein allowing the starving one of the threads to be woken and execute includes putting the starving one of the threads at the front of the wait queue; and returning to allowing the threads to steal the protected resources when the starved one of the threads uses the protected resources. - View Dependent Claims (16, 17)
-
Specification