#include <stdio.h>
#include <stdlib.h>
#include "chplcomm.h"
#include "chplexit.h"
#include "chplmem.h"
#include "chplrt.h"
#include "gdb.h"

#undef exit

static void _chpl_exit_common(int status, int all) {
  fflush(stdout);
  fflush(stderr);
  if (status != 0) {
    gdbShouldBreakHere();
  }
  if (all) {
    _chpl_comm_barrier("_chpl_comm_exit_all");
    exitChplThreads();         // tear down the threads
    _chpl_comm_exit_all(status);
  } else {
    _chpl_comm_exit_any(status);
  }
  exit(status);
}


void _chpl_exit_all(int status) {
  printFinalMemStat(0, 0);   // print the final memory statistics
  _chpl_exit_common(status, 1);
}


void _chpl_exit_any(int status) {
  _chpl_exit_common(status, 0);
}

#include <stdio.h>
#include <stdlib.h>
#include "chplcomm.h"
#include "chplexit.h"
#include "chplmem.h"
#include "chplrt.h"
#include "gdb.h"

#undef exit

static void _chpl_exit_common(int status, int all) {
  fflush(stdout);
  fflush(stderr);
  if (status != 0) {
    gdbShouldBreakHere();
  }
  if (all) {
    exitChplThreads();         // tear down the threads
  }
  if (all) {
    _chpl_comm_barrier("_chpl_comm_exit_all");
    _chpl_comm_exit_all(status);
  } else {
    _chpl_comm_exit_any(status);
  }
  exit(status);
}


void _chpl_exit_all(int status) {
  printFinalMemStat(0, 0);   // print the final memory statistics
  _chpl_exit_common(status, 1);
}


void _chpl_exit_any(int status) {
  _chpl_exit_common(status, 0);
}

--- 
+++ 
@@ -15,10 +15,8 @@
     gdbShouldBreakHere();
   }
   if (all) {
+    _chpl_comm_barrier("_chpl_comm_exit_all");
     exitChplThreads();         // tear down the threads
-  }
-  if (all) {
-    _chpl_comm_barrier("_chpl_comm_exit_all");
     _chpl_comm_exit_all(status);
   } else {
     _chpl_comm_exit_any(status);
Move a call to exitChplThreads() to after the final barrier

When it was before the barrier, all nodes except 0 called it very early, but
it should only be called at the very end of execution.


git-svn-id: 88467cb1fb04b8a755be7e1ee1026be4190196ef@15138 3a8e244f-b0f2-452b-bcba-4c88e055c3ca
