I'm not sure if this is even a sensible question. I was wondering if the following code can ever print a 1.
And the output on several runs has always been: 0 0 0 0 0
My aim in this program is to let all the threads run line 1 and sleep. After that, I hoped to see a thread modify count and sleep. Now, the former scenario having occured, all the threads must print a value greater than 0. Am I right in my thinking? This problem is not a real-world development problem, its just a thing that came into my mind. [ November 17, 2006: Message edited by: Allen Sylvester ]
Each thread has it's own local copy. Local objects are allocated in thread's stack not in heap. So any modification you make on local member of one thread will not be visible to other thread. You need common shared object if you want threads to interact.
What you are trying to accomplish is this
[ November 17, 2006: Message edited by: Purushothaman Thambu ]