Prevent Simultaneous Execution of Processes
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, often however, one single process or chain can only run once or when multiple other processes or chains have completed.
To prevent processes or chains from running at the same time, locks can be used. 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, process, and chain have lock counts, defaulting to 1
, which allow you to tailor which type of process can run simultaneously. Each process or chain holding a lock also holds a certain number of lock counts; when a process or chain require more lock counts than are currently available on the lock, it will not start until the required amount is freed. For example, three processes are scheduled to run now, all hold a lock which has 10
lock counts. The first two processes require 5
lock counts each, the third requires 6
. If the third process gets hold of the lock first, the other two will not run until the third has reached a final state.
An alternative solution, which is recommended for locking a great number of processes, would be to use a queue with a queue limit of 1
, so only one process can run in the queue at any given time. 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.