About Locks
Multiple processes can be scheduled to run across the scheduling landscape at any given time. Some of these processes or Chains have dependencies that must be met and that forbid simultaneous execution. One simple way is to create a Chain that executes the Chain Processes in a specific order. Sometimes, though, a single process or Chain can only run once or when multiple other processes or Chains have completed.
Locks let you prevent processes or Chains from running at the same time. A lock is an object that can be attached to a process or Chain and that prevents other processes or Chains with that same lock from starting as long as a process with that lock is running. Locks, processes, and Chains have a lock count that defaults to one. This lets you tailor which type of process can run simultaneously. Each process or Chain holding a lock also holds a certain lock count. When a process or Chain require more locks than are currently available, it will not start until the required number of locks is freed.
For example, assume that three processes are scheduled to run immediately, and each of them holds a lock count of 10. The first two processes require a lock count of 5, and the third requires a lock count of 6. If the third process gets hold of the lock first, the other two processes will not run until the third has reached a final state.
An alternative solution, which is recommended for locking a great number of processes, is to use a Queue with a queue limit of one, so that only one process can run in the Queue at any given time.
Warning: When you have many processes waiting on a lock, you end up in a situation of lock contention; to avoid this, use Queues with limits instead.
Simple Locks
A simple lock can be held by only one process at a time.
Counted Locks
Counted locks allow you specify how many processes can hold the same lock simultaneously. The lock has a specific number of counts that can be held by processes. Each process that uses the lock attempts to get hold of a specific number of lock counts; if it succeeds it starts running and keeps hold of the lock counts until it reaches a final status. Note that if the value on the Process Definition exceeds the value on the lock, the process will never run.
-
Example 1: A lock has
40
lock counts and three processes are about to attempt to get hold of the lock. ProcessA
requires5
lock counts,B
requires30
, andC``10
. ProcessA
gets hold of5
lock counts,B
gets hold of30
, andC
is set to status LockWait as too few lock counts are available; it has to wait for eitherA
orB
to reach a final state before it can attempt to get hold of the lock again. By the timeB
reaches a final state, processA
is still running, processesD
andE
(both requiring15
lock counts each) are waiting withC
for the lock. The system treats all 3 requests sequentially, all three are rescheduled as soon asB
releases the lock counts, these are then distributed on a first come, first served basis. -
Example 2: A lock has
40
lock counts, processA
is holding15
, so25
are available. ProcessB
is scheduled and requires26
lock counts, it is set to LockWait. ProcessesC
is scheduled and requires10
lock counts, it is set to LockWait since processesB
is in LockWait and was the first of the two to request the lock ( first come, first served ). ProcessesB
andC
will start simultaneously as soon asA
has released the lock.
Shared Exclusive Locks
Shared exclusive locks are similar to counted locks. A shared exclusive lock has either a specific number of lock counts, or an unlimited number. Processes request either a shared or an exclusive hold on the lock.
-
A shared hold always equates to holding a lock count of one.
-
An exclusive hold equates to holding the entire lock count.