POSIX streams and exit from a stream

I have two threads exchanging with each other; each thread uses 'while (1) ..'. Now I need the threads to exit with a certain condition, and so we end the application.

My question is: is it safe to just “return (NULL)” from the thread, or do I need to use the functions “pthread_exit” or “pthread_join” as well?

+3
source share
2 answers

It is safe to return null from stream functions; the code waiting for them should be ok.

POSIX talks about pthread_exit():

The implicit call to pthread_exit () is executed when a thread other than the thread in which main () was called returns from the initial procedure that was used to create it.

- pthread_join(), pthread_detach().

+3

pthread_exit(NULL) NULL . . , pthread_join , , pthread_detach .

+3

Source: https://habr.com/ru/post/1785108/


All Articles