Posix threads problem

后端 未结 6 923
暗喜
暗喜 2021-01-17 02:12

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

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-17 02:43

    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.

提交回复
热议问题