Architecture for a read/write thread lock
First Claim
1. A system for managing the use of a resource shared among concurrently-executing threads, said system comprising:
- a record for maintaining information as to whether any of said threads is accessing said resource at a given point in time, said record comprising a read counter and a write counter;
an object, which comprises or references;
a constructor, said constructor comprising computer-executable instructions to obtain a lock on said resource, to record said lock in said record, to increment said read counter when any of said threads reads from said resource, and to increment said write counter when any of said threads writes to said resource; and
a destructor, said destructor comprising a set of computer-executable instructions to release said lock, to record the release of said lock in said record, and to decrement said read counter and said write counter;
wherein the constructor instructions are executed upon creation of an instance of said object within a local scope, wherein the destructor instructions are executed upon the exiting of said local scope, and wherein no instruction, other than the instruction to exit said local scope, is required to release said lock.
13 Assignments
0 Petitions
Accused Products
Abstract
An architecture for a read/write thread lock is provided for use in a computing environment where several sets of computer instructions, or “threads,” can execute concurrently. The disclosed thread lock allows concurrently-executing threads to share access to a resource, such as a data object. The thread lock allows a plurality of threads to read from a resource at the same time, while providing a thread exclusive access to the resource when that thread is writing to the resource. The thread lock uses critical sections to suspend execution of other threads when one thread needs exclusive access to the resource. Additionally, a technique is provided whereby the invention can be deployed as constructors and destructors in a programming language, such as C++, where constructors and destructors are available. When the invention is deployed in such a manner, it is possible for a programmer to issue an instruction to lock a resource, without having to issue a corresponding unlock instruction.
61 Citations
31 Claims
-
1. A system for managing the use of a resource shared among concurrently-executing threads, said system comprising:
-
a record for maintaining information as to whether any of said threads is accessing said resource at a given point in time, said record comprising a read counter and a write counter; an object, which comprises or references; a constructor, said constructor comprising computer-executable instructions to obtain a lock on said resource, to record said lock in said record, to increment said read counter when any of said threads reads from said resource, and to increment said write counter when any of said threads writes to said resource; and a destructor, said destructor comprising a set of computer-executable instructions to release said lock, to record the release of said lock in said record, and to decrement said read counter and said write counter; wherein the constructor instructions are executed upon creation of an instance of said object within a local scope, wherein the destructor instructions are executed upon the exiting of said local scope, and wherein no instruction, other than the instruction to exit said local scope, is required to release said lock. - View Dependent Claims (2, 3, 4, 5, 6)
-
-
7. A method of managing a resource shared among a plurality of concurrently-executing threads, comprising the acts of:
-
claiming a first critical section, using a class object that is instantiated as a result of a lock request, the lock request being made by instantiating an instance of a class, the constructor for the class causing the first critical section to be claimed, wherein said first critical section is unavailable to a thread seeking to do a write to said resource and to a thread seeking to do a read from said resource whenever any of said threads is presently writing to said resource, and wherein said first critical section is available within a short time period, and no later than when one or more other threads that are not writing to said resource have relinquished said first critical section as a result of said other threads determining that said other threads are not requesting a write lock, to a thread seeking to do a write to said resource and to a thread seeking to do a read from said resource whenever none of said threads is presently writing to said resource; if said first critical section is unavailable, waiting at least until said first critical section becomes available; claiming a second critical section, wherein said second critical section is unavailable to a thread seeking to do a write to said resource whenever any of said threads is presently reading from said resource; if said second critical section is unavailable, waiting at least until said second critical section becomes available; and executing at least one instruction that accesses said resources wherein the method further comprises; creating a local class instance; and after said executing said executed instruction, destroying said local class instance; wherein said claiming acts are invoked by the constructor for said local class instance, and wherein the destructor for said local class instance relinquishes at least one of said critical sections. - View Dependent Claims (8, 9, 10, 11, 12, 13, 14, 15, 16)
-
-
17. A computer-readable medium having computer-executable instructions to perform a method of managing a resource shared among a plurality of concurrently-executing threads, said method comprising:
-
claiming a first critical section, using a class object that is instantiated as a result of a lock request, the lock request being made by instantiating an instance of a class, the constructor for the class causing the first critical section to be claimed, wherein said first critical section is unavailable to a thread seeking to do a write to said resource and to a thread seeking to do a read from said resource whenever any of said threads is presently writing to said resource, and wherein said first critical section is always available to a thread seeking to do a write to said resource and to a thread seeking to do a read from said resource whenever none of said threads is presently writing to said resource; if said first critical section is unavailable, waiting at least until said first critical section becomes available; claiming a second critical section, wherein said second critical section is unavailable to a thread seeking to do a write to said resource whenever any of said threads is presently reading from said resource; if said second critical section is unavailable, waiting at least until said second critical section becomes available; and executing at least one instruction that accesses said resource; wherein the method further comprises; creating a local class instance; and after said executing said executed instruction, destroying said local class instance; wherein said claiming acts are invoked by the constructor for said local class instance, and wherein the destructor for said local class instance relinquishes at least one of said critical sections.
-
-
18. A method of managing a resource in a computer environment that supports concurrent execution of a plurality of sets of computer-executable instructions, said method comprising:
in a one of said sets of instructions; opening a local scope; creating an object instance within said local scope, wherein said instance comprises or references a constructor method, and wherein said constructor method comprises instructions to obtain a read lock or a write lock on said resource, to increment a read counter when obtaining said read lock, and to increment a write counter when obtaining said write lock; performing, subsequent to creating said instance, one or more operations, wherein at least one of said operations reads from or writes to said resource; and
, when none of said plurality of sets of computer executed instructions seeks to read from or write to said resource,closing said local scope, whereupon said instance is destroyed, said instance further comprising or referencing a destructor method, and wherein said destructor method comprises instructions to release said read lock or said write lock. - View Dependent Claims (19, 20, 21, 22, 23)
-
24. A computer-readable medium having computer-executable instructions to perform a method of managing a resource in a computer environment that supports concurrent execution of a plurality of sets of computer-executable instructions, said method comprising:
in a one of said sets of instructions; opening a local scope; creating an object instance within said local scope, wherein said instance comprises or references a constructor method, and wherein said constructor method comprises instructions to obtain a read lock or a write lock on said resource, to increment a read counter when obtaining said read lock, and to increment a write counter when obtaining said write lock; performing, subsequent to creating said instance, one or more operations, wherein at least one of said operations reads from or writes to said resource; and
, when none of said plurality of sets of computer executed instructions seeks to read from or write to said resource,closing said local scope, whereupon said instance is destroyed, said instance further comprising or referencing a destructor method, and wherein said destructor method comprises instructions to release said read lock or said write lock.
-
25. A method of managing a resource in a computing environment that supports concurrent execution of a plurality of sets of computer-executable instructions, said method comprising:
-
(a) issuing, in a first of said sets of instructions, a first request for said first of said sets of instructions to obtain a lock on said resource, wherein said request comprises an indication as to whether said set of instructions needs a read lock on said resource or a write lock on said resource, and wherein said request is issued by creating a local class instance, wherein a constructor for said class instance issues said request; (b) claiming a first critical section, wherein said first critical section is unavailable to said first of said sets of instructions whenever any of said sets of instructions is presently writing to said resource, and wherein said first critical section is available within a short time period to said first of said sets of instructions whenever none of said sets of instructions is presently writing to said resource; (c) if said indication is that said first of said sets of instructions needs a write lock on said resource; (c)(1) claiming a second critical section; and (c)(2) relinquishing said second critical section; whereupon said write lock is granted to said first of said sets of instructions; (d) if said indication is that said first of said sets of instructions needs a read lock on said resource; (d)(1) relinquishing said first critical section; and (d)(2) if no other one of said plurality of sets of instructions, exclusive of said first of said sets of instructions, has a read lock on said resource, claiming said second critical section; whereupon said read lock is granted to said first of said sets of instructions (e) issuing, in said first of said sets of instructions, a second request to release said lock; (f) if said lock is a read lock and no other one of said sets of instructions, exclusive of said first of said sets of instructions, presently has a read lock on said resource, relinquishing said second critical section; and (g) if said lock is a write lock, relinquishing said first critical section; and wherein the method further comprises; destroying said local class instance, wherein said second request is issued by the destructor for said class instance. - View Dependent Claims (26, 27, 28, 29, 30)
-
-
31. A computer-readable medium having computer-executable instructions to perform a method of managing a resource in a computing environment that supports concurrent execution of a plurality of sets of computer-executable instructions, said method comprising:
-
(a) issuing, in a first of said sets of instructions, a first request for said first of said sets of instructions to obtain a lock on said resource, wherein said request comprises an indication as to whether said set of instructions needs a read lock on said resource or a write lock on said resource, and wherein said request is issued by creating a local class instance, wherein a constructor for said class instance issues said request; (b) claiming a first critical section, wherein said first critical section is unavailable to said first of said sets of instructions whenever any of said sets of instructions is presently writing to said resource, and wherein said first critical section is made available to said first of said sets of instructions whenever none of said sets of instructions is presently writing to said resource; (c) if said indication is that said first of said sets of instructions needs a write lock on said resource; (c)(1) claiming a second critical section; and (c)(2) relinquishing said second critical section; whereupon said write lock is granted to said first of said sets of instructions; (d) if said indication is that said first of said sets of instructions needs a read lock on said resource; (d)(1) relinquishing said first critical section; and (d)(2) if no other one of said plurality of sets of instructions, exclusive of said first of said sets of instructions, has a read lock on said resource, claiming said second critical section; whereupon said read lock is granted to said first of said sets of instructions (e) issuing, in said first of said sets of instructions, a second request to release said lock; (f) if said lock is a read lock and no other one of said sets of instructions, exclusive of said first of said sets of instructions, presently has a read lock on said resource, relinquishing said second critical section; and (g) if said lock is a write lock, relinquishing said first critical section; and wherein the method further comprises; destroying said local class instance, wherein said second request is issued by the destructor for said class instance.
-
Specification