This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Senthil Kumar Sekar wrote:Does Main thread runs parallely with the thread being created in the same thread?
Yes. That's the whole point of multithreading.
However, that doesn't mean that both threads will be executing simultaneously. Depending on the hardware, the OS, what else is running on the system, and the threads' mix of CPU and I/O, they may run simultaneously, or they may take turns, or one may run to completion before the other one even starts. We can't predict that and we can't control it.
In your case, the main thread could look at the "b" variable before the other thread starts, after it's done, or anywhere in between. Also, since b is not declared volatile and you don't use syncing, any value the the second thread writes to b might not be visible to the main thread right away--if it reads b, it may still see the previous value.