Multiple threads in C program

前端 未结 5 1233
北海茫月
北海茫月 2020-12-19 12:10

I\'m writing a Unix application in C which uses multiple threads of control. I\'m having a problem with the main function terminating before the thread it has spawned have a

5条回答
  •  [愿得一人]
    2020-12-19 12:25

    Yes one of doing this is to use pthread_join function: that's assuming your thread is in "joinable" state.

    • pthread_create: after this function returns control, your thread will be executing your thread function.

    • after pthread_create, use the tid from pthread_create to pthread__join.

    If your thread is detached, you must use some other technique e.g. shared variable, waiting on signal(s), shared queue etc.

    Great reference material available here.

提交回复
热议问题