Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Difference between std::quick_exit and std::abort

  • Last Updated : 15 Oct, 2018


It Causes normal program termination to occur without completely cleaning the resources.
Syntax :

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
 void quick_exit(int exit_code) no except; 

In case of execution of threads the codes becomes complex and knowing the execution of threads is hard. While one the thread might be waiting for a process to end while the other thread is waiting for the previous thread. In such cases real programs usually deadlock and exit which isn’t pleasant. The admin must force start the system or close the user interface etc to come out of the lock. For this purposes the std::quick_exit() was made. It terminates the program saving us from the hard part of coming out of a deadlock while executing a real program. It clears the IO but does not flush the static destructors. Another function at_quick_exit()

 int at_quick_exit( void (*func)(void) ); 

takes a functions as parameter which is to be executed when the quick_exit() function is called. The functions registered to this are called on the reverse order of their execution.

#include <cstdlib>
void atEXIT()
  cout << "Quick exit function.";
int main ()
  cout << "Main Function";
  cout << "End of Main"; 
  return 0;
 Output:  Main Function
          Quick exit function.    


Causes abnormal program termination unless SIGABRT is being caught by a signal handler passed to std::signal and the handler does not return.

 void abort() no except; 

POSIX specifies that the abort function overrides blocking or ignoring the SIGABRT signal.

#include <cstdlib>

int main ()
  FILE * fp;
  fp= fopen("myfile.txt", "r");
  if (fp== NULL)
    fputs("Error opening file \n", stderr);
  return 0;
 Output:  The file named myfile.txt, if not found or fails opens due to any reason the error 
            message is printed and abort function terminates the program.

Similarities : Both the std::quick_exit() and std::abort() functions are defined in the cstdlib header. Both of these functions have no parameters and no exceptions. They both have no return value as well. They are used for termination of the program but they still are different from each other.
Differences : The reason for introducing the quick_exit() function was to end the running program while clearing the IO and still getting some part of the program i.e. the functions registered in at_quick_exit() to be executed whereas the std::abort() function terminates the program without executing furthermore part of the program and not clearing the IO.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!