Why does start_routine for pthread_create return void* and take void*

后端 未结 2 1345
伪装坚强ぢ
伪装坚强ぢ 2020-12-29 20:31

The function header for pthread_create looks like this:

int pthread_create(pthread_t * thread, 
                   const pthread_attr_t * attr,
          


        
相关标签:
2条回答
  • 2020-12-29 21:06

    From the documentation for pthread_create:

    The thread is created executing start_routine with arg as its sole argument. If the start_routine returns, the effect is as if there was an implicit call to pthread_exit() using the return value of start_routine as the exit status. Note that the thread in which main() was originally invoked differs from this. When it returns from main(), the effect is as if there was an implicit call to exit() using the return value of main() as the exit status.

    And pthread_exit:

    The pthread_exit() function terminates the calling thread and makes the value value_ptr available to any successful join with the terminating thread.

    So if you do a pthread_join on a thread, the pointer it returns is passed back to the joining thread, allowing you to transmit information from the dying thread to another, living thread.

    0 讨论(0)
  • 2020-12-29 21:13

    From the spec:

    If the start_routine returns, the effect is as if there was an implicit call to pthread_exit() using the return value of start_routine as the exit status.

    0 讨论(0)
提交回复
热议问题