Question

Under maintenance, I see that the project code (in c/c++ on linux) calls libc exit function in-case of some un-recoverable error. However, this process termination call is used across multiple threads (each when it faces unrecoverable scenario). Now -

  • Can the process exit be called from thread other than main thread without any side effects.
  • Whenever exit is called (either in main thread or any other thread), does it guarantee graceful exit of the threads.

I understand that the standard (man pages) is silent about it, and the best way to do is, initiate a graceful termination of all threads and using notification mechanism, main thread must be notified for graceful termination. However, since it is a project under maintenance, want to check if current behavior is correct before changing.

Issue I am facing is, I can see random crashes where one of the thread is under the due process of exit call execution.

Was it helpful?

Solution

For the first question, when you call exit (from any thread, main or child) the process exits immediately.

For the second question, see the answer above. In short, no. Threads will not exit "gracefully" (from the applications perspective anyway).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top