February 2014
Beginner
1248 pages
62h 25m
English
The output errors of Fig. 23.7 can be attributed to the fact that the shared object, SimpleArray, is not thread safe—SimpleArray is susceptible to errors if it’s accessed concurrently by multiple threads. The problem lies in method add, which stores the value of writeIndex, places a new value in that element, then increments writeIndex. Such a method would present no problem in a single-threaded program. However, if one thread obtains the value of writeIndex, there’s no guarantee that another thread cannot come along and increment writeIndex before the first thread has had a chance to place a value in the array. If this happens, the first thread will be writing to the array based ...
Read now
Unlock full access