1 /* -----------------------------------------------------------------------------
2 * $Id: Main.c,v 1.27 2001/03/22 03:51:10 hwloidl Exp $
4 * (c) The GHC Team 1998-2000
6 * Main function for a standalone Haskell program.
8 * ---------------------------------------------------------------------------*/
10 #define COMPILING_RTS_MAIN
20 # include "Printer.h" /* for printing */
24 # include "Assembler.h"
28 # include "Parallel.h"
29 # include "ParallelRts.h"
33 #if defined(GRAN) || defined(PAR)
34 # include "GranSimRts.h"
41 extern void __init_PrelMain(void);
43 /* Hack: we assume that we're building a batch-mode system unless
46 #ifndef INTERPRETER /* Hack */
47 int main(int argc, char *argv[])
50 SchedulerStatus status;
51 /* all GranSim/GUM init is done in startupHaskell; sets IAmMainThread! */
53 startupHaskell(argc,argv,__init_PrelMain);
55 /* kick off the computation by creating the main thread with a pointer
56 to mainIO_closure representing the computation of the overall program;
57 then enter the scheduler with this thread and off we go;
59 the same for GranSim (we have only one instance of this code)
61 in a parallel setup, where we have many instances of this code
62 running on different PEs, we should do this only for the main PE
63 (IAmMainThread is set in startupHaskell)
69 { /* a wait loop to allow attachment of gdb to UNIX threads */
72 for (i=0, s=0; i<(nat)RtsFlags.ParFlags.wait; i++)
73 for (j=0; j<1000000; j++)
77 belch("Passed wait loop"));
80 if (IAmMainThread == rtsTrue) {
82 fprintf(stderr, "==== [%x] Main Thread Started ...\n", mytid));
84 /* ToDo: Dump event for the main thread */
85 status = rts_evalIO((HaskellObj)mainIO_closure, NULL);
87 /* Just to show we're alive */
89 fprintf(stderr, "== [%x] Non-Main PE enters scheduler via taskStart() without work ...\n",
92 /* all non-main threads enter the scheduler without work */
94 status = Success; // declare victory (see shutdownParallelSystem)
99 /* ToDo: Dump event for the main thread */
100 status = rts_evalIO(mainIO_closure, NULL);
102 # else /* !PAR && !GRAN */
104 /* ToDo: want to start with a larger stack size */
105 status = rts_evalIO((HaskellObj)mainIO_closure, NULL);
107 # endif /* !PAR && !GRAN */
109 /* check the status of the entire Haskell computation */
112 prog_belch("no threads to run: infinite loop or deadlock?");
113 exit_status = EXIT_DEADLOCK;
116 prog_belch("main thread exited (uncaught exception)");
117 exit_status = EXIT_KILLED;
120 prog_belch("interrupted");
121 exit_status = EXIT_INTERRUPTED;
124 exit_status = EXIT_SUCCESS;
128 prog_belch("main thread PE killed; probably due to failure of another PE; check /tmp/pvml...");
129 exit_status = EXIT_KILLED;
133 barf("main thread completed with invalid status");
135 shutdownHaskellAndExit(exit_status);
136 return 0; /* never reached, keep gcc -Wall happy */
138 # endif /* BATCH_MODE */