Thread Limit


Thread Limit

The Thread Limit object is used to wait until the number of currently executing threads undergoes a specified value. This is especially useful for multiprocessor machines where the number of parallel executing threads should match the number of processors. This can also be used for single processor machines with the so-called Hyper-Threading, where two threads one a single processor can lead to increased performance.

The normal use of a Thread Limit object is in a loop which for example reads in data and where after the Thread Limit object a new thread is created to process the data. This is especially useful when using parallel calculator objects which can be executed by multiple threads at the same time. Use the property dialog to specify the maximum number of executing threads. If the number of currently executing threads is bigger than the given value, the current thread is suspended until enough threads have terminated so that the number of threads is less or equal the specified value.

Don't use the Thread Limit object like a Thread Blocker, as this will probably cause a deadlock!. As the Thread Limit suspends execution of the current thread it should not be called by more than one thread at the same time. Imagine this situation: The "Max. Threads"-property is 1 and the number of threads is bigger than one and one thread is already waiting at the Thread Limit object. If the execution of another thread reaches the same Thread Limit object, it is also suspended because of the Thread Limit objects own mutex which prevents multiple execution of the same object. Now two threads are waiting and even if all other threads terminate the number of executing threads will never go below 2.


The Vimms User Manual