Order of running threads in pthreads

后端 未结 4 1638
挽巷
挽巷 2021-01-26 11:58

In the following program, what are the possibilities for the ordering of threads? Assuming \"function\" will print thread id which is unique (since here we have only one process

4条回答
  •  情歌与酒
    2021-01-26 12:41

    The only ordering guarantees here are that pthread_join(th1, NULL); will not return until thread 1 has exited and pthread_join(th2, NULL); will not return until thread 2 has exited. Consequently, the main() function will not return (and the process will not exit) until both thread 1 and thread 2 have exited.

    There is no ordering imposed between thread 1 and thread 2 - their execution can be arbitrarily interleaved.

提交回复
热议问题