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 40lock counts and three processes are about to attempt to get hold of the lock. Process A requires 5lock counts, B requires 30, and C``10. Process A gets hold of 5lock counts, B gets hold of 30, and C is set to status LockWait as too few lock counts are available; it has to wait for either A or B to reach a final state before it can attempt to get hold of the lock again. By the time B reaches a final state, process A is still running, processes D and E (both requiring 15lock counts each) are waiting with C for the lock. The system treats all 3 requests sequentially, all three are rescheduled as soon as B releases the lock counts, these are then distributed on a first come, first served basis.

  • Example 2: A lock has 40lock counts, process A is holding 15, so 25 are available. Process B is scheduled and requires 26lock counts, it is set to LockWait. Processes C is scheduled and requires 10lock counts, it is set to LockWait since processes B is in LockWait and was the first of the two to request the lock ( first come, first served ). Processes B and C will start simultaneously as soon as A 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.