1 /* -----------------------------------------------------------------------------
2 * $Id: Main.c,v 1.39 2003/07/10 08:02:29 simonpj Exp $
4 * (c) The GHC Team 1998-2000
6 * Main function for a standalone Haskell program.
8 * ---------------------------------------------------------------------------*/
10 #define COMPILING_RTS_MAIN
12 #include "PosixSource.h"
23 # include "Printer.h" /* for printing */
27 # include "Assembler.h"
31 # include "Parallel.h"
32 # include "ParallelRts.h"
36 #if defined(GRAN) || defined(PAR)
37 # include "GranSimRts.h"
44 extern void __stginit_ZCMain(void);
46 /* Hack: we assume that we're building a batch-mode system unless
49 #ifndef INTERPRETER /* Hack */
50 int main(int argc, char *argv[])
53 SchedulerStatus status;
54 /* all GranSim/GUM init is done in startupHaskell; sets IAmMainThread! */
56 startupHaskell(argc,argv,__stginit_ZCMain);
58 /* kick off the computation by creating the main thread with a pointer
59 to mainIO_closure representing the computation of the overall program;
60 then enter the scheduler with this thread and off we go;
62 the same for GranSim (we have only one instance of this code)
64 in a parallel setup, where we have many instances of this code
65 running on different PEs, we should do this only for the main PE
66 (IAmMainThread is set in startupHaskell)
72 { /* a wait loop to allow attachment of gdb to UNIX threads */
75 for (i=0, s=0; i<(nat)RtsFlags.ParFlags.wait; i++)
76 for (j=0; j<1000000; j++)
80 belch("Passed wait loop"));
83 if (IAmMainThread == rtsTrue) {
85 fprintf(stderr, "==== [%x] Main Thread Started ...\n", mytid));
87 /* ToDo: Dump event for the main thread */
88 status = rts_mainLazyIO((HaskellObj)mainIO_closure, NULL);
90 /* Just to show we're alive */
92 fprintf(stderr, "== [%x] Non-Main PE enters scheduler via taskStart() without work ...\n",
95 /* all non-main threads enter the scheduler without work */
97 status = Success; // declare victory (see shutdownParallelSystem)
102 /* ToDo: Dump event for the main thread */
103 status = rts_mainLazyIO(mainIO_closure, NULL);
105 # else /* !PAR && !GRAN */
107 /* ToDo: want to start with a larger stack size */
108 status = rts_mainLazyIO((HaskellObj)mainIO_closure, NULL);
110 # endif /* !PAR && !GRAN */
112 /* check the status of the entire Haskell computation */
115 prog_belch("main thread exited (uncaught exception)");
116 exit_status = EXIT_KILLED;
119 prog_belch("interrupted");
120 exit_status = EXIT_INTERRUPTED;
123 exit_status = EXIT_SUCCESS;
127 prog_belch("main thread PE killed; probably due to failure of another PE; check /tmp/pvml...");
128 exit_status = EXIT_KILLED;
132 barf("main thread completed with invalid status");
134 shutdownHaskellAndExit(exit_status);
135 return 0; /* never reached, keep gcc -Wall happy */
137 # endif /* BATCH_MODE */