1 /* -----------------------------------------------------------------------------
2 * $Id: Main.c,v 1.36 2003/03/17 14:47:47 simonmar 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"
22 # include "Printer.h" /* for printing */
26 # include "Assembler.h"
30 # include "Parallel.h"
31 # include "ParallelRts.h"
35 #if defined(GRAN) || defined(PAR)
36 # include "GranSimRts.h"
43 extern void __stginit_Main(void);
45 /* Hack: we assume that we're building a batch-mode system unless
48 #ifndef INTERPRETER /* Hack */
49 int main(int argc, char *argv[])
52 SchedulerStatus status;
53 /* all GranSim/GUM init is done in startupHaskell; sets IAmMainThread! */
55 startupHaskell(argc,argv,__stginit_Main);
57 /* kick off the computation by creating the main thread with a pointer
58 to mainIO_closure representing the computation of the overall program;
59 then enter the scheduler with this thread and off we go;
61 the same for GranSim (we have only one instance of this code)
63 in a parallel setup, where we have many instances of this code
64 running on different PEs, we should do this only for the main PE
65 (IAmMainThread is set in startupHaskell)
71 { /* a wait loop to allow attachment of gdb to UNIX threads */
74 for (i=0, s=0; i<(nat)RtsFlags.ParFlags.wait; i++)
75 for (j=0; j<1000000; j++)
79 belch("Passed wait loop"));
82 if (IAmMainThread == rtsTrue) {
84 fprintf(stderr, "==== [%x] Main Thread Started ...\n", mytid));
86 /* ToDo: Dump event for the main thread */
87 status = rts_mainLazyIO((HaskellObj)mainIO_closure, NULL);
89 /* Just to show we're alive */
91 fprintf(stderr, "== [%x] Non-Main PE enters scheduler via taskStart() without work ...\n",
94 /* all non-main threads enter the scheduler without work */
96 status = Success; // declare victory (see shutdownParallelSystem)
101 /* ToDo: Dump event for the main thread */
102 status = rts_mainLazyIO(mainIO_closure, NULL);
104 # else /* !PAR && !GRAN */
106 /* ToDo: want to start with a larger stack size */
107 status = rts_mainLazyIO((HaskellObj)mainIO_closure, NULL);
109 # endif /* !PAR && !GRAN */
111 /* check the status of the entire Haskell computation */
114 prog_belch("main thread exited (uncaught exception)");
115 exit_status = EXIT_KILLED;
118 prog_belch("interrupted");
119 exit_status = EXIT_INTERRUPTED;
122 exit_status = EXIT_SUCCESS;
126 prog_belch("main thread PE killed; probably due to failure of another PE; check /tmp/pvml...");
127 exit_status = EXIT_KILLED;
131 barf("main thread completed with invalid status");
133 shutdownHaskellAndExit(exit_status);
134 return 0; /* never reached, keep gcc -Wall happy */
136 # endif /* BATCH_MODE */