pthreads in C - pthread_exit

前端 未结 9 1382
北荒
北荒 2021-02-05 14:03

For some reason I thought that calling pthread_exit(NULL) at the end of a main function would guarantee that all running threads (at least created in the main funct

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-05 14:19

    Quite aside from whether the program should or should not terminate when the main thread calls pthread_exit, pthread_exit says

    The pthread_exit() function terminates the calling thread

    And also:

    After a thread has terminated, the result of access to local (auto) variables of the thread is undefined.

    Since the context is an automatic variable of main(), your code can fall over before it even gets to the point of testing what you want it to test...

提交回复
热议问题