Process::terminate() still not right


#1

Looking at the behavior of ::exit()] it seems juce::Process::terminate() is still not doing the right thing. The docs for terminate state:

    /** Kills the current process immediately.

        This is an emergency process terminator that kills the application
        immediately - it's intended only for use only when something goes
        horribly wrong.

And I agree with this. but exit() is not the way to do it. You probably want abort or _exit

It seems only Windows has the right implementation of Process::terminate()


#2

Yes, good point. To be honest, I’m not sure why I ever added Process::terminate, as it’s pretty much a functional equivalent of std::terminate.


#3

I didnt even know about std::terminate, you da man Jules!


#4

Still not right. ::_exit(EXIT_FAILURE) or std::_Exit(EXIT_FAILURE) is what you want.

Try it here:
http://ideone.com/3YOfRb

Change the #if to 1 or 0 to suit your taste

Or try the code yourself:

#include <stdlib.h>
#include <csignal>
#include <cstdlib>
#include <exception>
#include <iostream>

void print (char const* msg) { std::cout << msg << std::endl; }

void on_exit() { print("on_exit"); }

struct class_exit_t { ~class_exit_t() { print ("class_exit"); } };

class_exit_t class_exit;

void my_term () { print("my_term"); abort(); }

void on_abort(int) { print("on_abort"); }

int main ()
{
  atexit (&on_exit);
  signal(SIGABRT, &on_abort);
  std::set_terminate (&my_term);

#if 0
  _Exit(EXIT_FAILURE);
#else
  std::terminate ();
#endif

  return 0;
}

#5

std::exit, std::terminate, std::abort, std::_Exit, _exit, ::exit. The standard’s a total fucking mess when it comes to this stuff. I guess std::_Exit is the way to go then.


#6

Who’d have thought exiting the program was so hard? LOL


#7

Why isn’t Process::terminate marked JUCE_CALLTYPE in juce_posix_SharedCode.h?