In a multi-domain computer system in which several processes are running,
a composite lock provides mutually exclusive access to a resource. The
composite lock has a back-end component and a front-end component. The
back-end component is platform-dependent and operates as a semaphore,
with Wait and Signal functions. The front-end component conditionally
calls the Wait and Signal functions depending on whether the lock is
currently contested when a new process wishes to acquire the lock, and on
whether any process is currently suspended, waiting to acquire the lock.
The front-end and back-end components may execute in different domains.
In the uncontested case, the invention avoids costly domain crossings.
The front-end component may also include a spinning feature to further
reduce the need to invoke the back-end component and cause a domain
crossing. The composite lock is particularly advantageous in computer
systems that include a virtual machine.