∟Application Data Shared by Multiple Threads - Test Results
This section provides test results of a tutorial example on how to share application data by multiple threads. Data sharing allows multiple threads to work together on a single large task.
I performed several tests with the program presented in the previous section. Testing outputs are listed below.
As expected, the total execution time is slowly growing as more threads are added
to the program. Because there is only CPU, when one thread executes, the others
must wait. The small amount of extra execution time when more threads are added
is the overhead of managing more threads.
However, there is one surprise in the output. One execution of the program with
10 threads took only 3925 milliseconds, comparing to 6750 milliseconds for another
execution with the same number of threads. What happened for that execution, and why
it went so fast? I don't know the answers. May be, the operating system was giving
my application some extra CPU resource by blocking other applications longer.
The outputs also show that threads can be blocked for relatively longer period of
time by other threads by the application, even they all have the same priority.
One example in the output of the execution with 15 threads is that threads 4, 5, 6
and 7 were blocked at the start line until thread 1 had already checked and/or
processed 638 years.