After mtaDequeueStart() performs any necessary initialization steps, it then starts a loop whereby it communicates with the MTA Job Controller. Based upon information from the Job Controller, it then creates zero or more execution threads to process queued messages.
While any execution threads are running, the thread that invoked mtaDequeueStart()(the primal thread) executes a loop containing a brief pause (that is, a sleep request). Each time the primal thread awakens, it communicates with the Job Controller to see if it should create more execution threads. In addition, the Job Controller itself has logic to determine if more threads are needed in the currently running channel program, or if it should create additional processes to run the same channel program.
To demonstrate, the following code example shows pseudo-code of the mtaDequeueStart() loop.
threads_running = 0 threads_max = MTA_THREAD_MAX_THREADS attemtps = MTA_JBC_MAX_ATTEMPTS LOOP: while (threads_running < threads_max) { Go to DONE if a shut down has been requested pending_messages = Ask the Job Controller how many messsages there are to be processed // If there are no pending messages // then consider what to do next if (pending_messages = 0) { // Continue to wait? if (attempts <= 0) go to DONE // Decrement attempts and wait attempts = attempts - 1; go to SLEEP } // Reset the attempts counter attempts = MTA_JBC_MAX_ATTEMPTS threads_needed = Ask the Job Controller how many processing threads are needed // Cannot run more then threads_max threads per process if (threads_needed \> threads_max) threads_needed = threads_max // Create additional threads if needed if (threads_needed \> threads_running) { Create (threads_needed - threads_running) more threads threads_running = threads_needed } } SLEEP: Sleep for MTA_JBC_RETRY_INTERVAL seconds -- a shut down request will cancel the sleep go to LOOP DONE: Wait up to MTA_THREAD_WAIT_TIMEOUT seconds for all processing threads to exit Return to the caller of mtaDequeueStart() |