I have sort of a homework and it asks me to end the program gracefully without explicit termination such as calling exit() or killing the threads.
However I cannot think of any other methods than return 0, so what are the methods to end a program gracefully?
I have sort of a homework and it asks me to end the program
Share
Killing the threads is absolutely not a graceful way to terminate a program. I think what your instructor means is that all your
parentthreads should wait on theirchildthreads before terminating themselves.Ideally, an explicit call
pthread_exitfrom the main thread would ensure that all it’s children continue running even after it exits. Refer to this link. But, the safest way to wait on your child threads before exiting is to usepthread_join.Nevertheless,
exit(0)is the graceful return for a process as such.