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
If you mean the order of the answers, yes, it will be different since which thread runs is decided by the Linux scheduler.
To elaborate: Once you create your threads, the order in which they get CPU time depends on the underlying OS scheduler(here, Linux scheduler). This may not be the same everytime.