Thread blocker

Thread Blocker

The thread blocker object prevents the unintentional creation of too many threads. This occurs normally when threads are created by user interaction: The scrollbar object for example can create a thread whenever its value changes. If running time of a thread created by user interaction is long, this would result in many simultaneuosly executing threads and a very slow response time.
Fig. 1: Two threads
A thread blocker object does the following: When executed it creates a new thread and waits until this has terminated. If the thread blocker is called again by a new thread with the old thread still running, the environment, i.e. all variable values of the new thread are saved and the new thread is finished. If now called again, with the first thread still running, the object keeps the environment of the new thread instead of the previous one and the new thread is also finished. Now, when the first thread terminates, the thread object remembers the it has been called in the mean time and restarts execution with the environment of the thread calling the last time.

Figure 1 shows an object layout example with the thread blocker object. Here it has the effect that if during execution of the calculator object multiple threads are created, only the last one is executed, all previous ones are discarded.

The Vimms User Manual