I am answering this 4 years later, but there is not an accepted answer, and the correct answer is "lost" within a long text. The correct answer is that the ONLY thing that is needed is to insert the code "a.join(); b.join();" right after the call to "b.start();". This will force the main thread of control to wait for the two spawned threads to finish before attempting to read the values in their respective count[] arrays, which will now be correctly visible by the main thread.