I am trying to understand pthreads by example. I have made the following code that is giving different answers everytime I run! Could anyone explain the bug please?
TIA,
Svi
The reason you don't see the other threads executing, as per your comments to the other answers is because your main() function (and hence your program) returns before the other threads have had an opportunity to execute. If you put a sleep(5) before your main() returns, you will see them execute.