Mechanism for implementing thread synchronization in a priority-correct, low-memory safe manner
First Claim
1. A machine implemented method, comprising:
- initializing a first thread, wherein initializing the first thread comprises allocating a first mutex and causing the first thread to obtain a lock on the first mutex, and allocating a first memory portion which is associated with the first thread as a first boost record;
initializing a second thread, wherein initializing the second thread comprises allocating a second mutex and causing the second thread to obtain a lock on the second mutex, and allocating a second memory portion which is associated with the second thread as a second boost record;
granting the first thread a lock on a target object;
detecting that the second thread wishes to lock the target object while the first thread owns the lock on the target object;
creating a heavy-weight lock (HL) data structure, which is associated with the target object;
disassociating the second boost record from the second thread and associating the second boost record with the HL data structure;
updating a boost queue in the second boost record to include the second thread; and
causing the second thread to wait on the first mutex and a cancel object, wherein the second thread is awakened if either the lock on the first mutex is released or the cancel object is signaled.
2 Assignments
0 Petitions
Accused Products
Abstract
A mechanism is disclosed for implementing fast locking in a multi-threaded system. This mechanism enables fast locking to be performed even on an operating system platform that does not allow one thread to assign ownership of a lock on a mutex to another thread. In addition, the mechanism performs locking in a manner that ensures priority correctness and is low-memory safe. In one implementation, the priority correctness is achieved by using operating system mutexes to implement locking, and the low-memory safe aspect is achieved by pre-allocating a memory section to each thread. This pre-allocated memory section ensures that a thread will have sufficient memory to obtain a lock, even when a system is in a low-memory state. With this mechanism, it is possible to implement locking in a safe and efficient manner.
18 Citations
20 Claims
-
1. A machine implemented method, comprising:
-
initializing a first thread, wherein initializing the first thread comprises allocating a first mutex and causing the first thread to obtain a lock on the first mutex, and allocating a first memory portion which is associated with the first thread as a first boost record; initializing a second thread, wherein initializing the second thread comprises allocating a second mutex and causing the second thread to obtain a lock on the second mutex, and allocating a second memory portion which is associated with the second thread as a second boost record; granting the first thread a lock on a target object; detecting that the second thread wishes to lock the target object while the first thread owns the lock on the target object; creating a heavy-weight lock (HL) data structure, which is associated with the target object; disassociating the second boost record from the second thread and associating the second boost record with the HL data structure; updating a boost queue in the second boost record to include the second thread; and causing the second thread to wait on the first mutex and a cancel object, wherein the second thread is awakened if either the lock on the first mutex is released or the cancel object is signaled. - View Dependent Claims (2, 3, 4, 5, 6, 7, 8, 9, 10)
-
-
11. A machine readable storage medium, comprising:
-
instructions for causing one or more processors to initialize a first thread, wherein initializing the first thread comprises allocating a first mutex and causing the first thread to obtain a lock on the first mutex, and allocating a first memory portion which is associated with the first thread as a first boost record; instructions for causing one or more processors to initialize a second thread, wherein initializing the second thread comprises allocating a second mutex and causing the second thread to obtain a lock on the second mutex, and allocating a second memory portion which is associated with the second thread as a second boost record; instructions for causing one or more processors to grant the first thread a lock on a target object; instructions for causing one or more processors to detect that the second thread wishes to lock the target object while the first thread owns the lock on the target object; instructions for causing one or more processors to create a heavy-weight lock (HL) data structure, which is associated with the target object; instructions for causing one or more processors to disassociate the second boost record from the second thread and to associate the second boost record with the HL data structure; instructions for causing one or more processors to update a boost queue in the second boost record to include the second thread; and instructions for causing one or more processors to cause the second thread to wait on the first mutex and a cancel object, wherein the second thread is awakened if either the lock on the first mutex is released or the cancel object is signaled. - View Dependent Claims (12, 13, 14, 15, 16, 17, 18, 19, 20)
-
Specification