1 /* -----------------------------------------------------------------------------
2 * $Id: Main.c,v 1.16 2000/01/14 13:38:54 simonmar Exp $
4 * (c) The GHC Team 1998-1999
6 * Main function for a standalone Haskell program.
8 * ---------------------------------------------------------------------------*/
10 #define COMPILING_RTS_MAIN
19 # include "Printer.h" /* for printing */
23 # include "Assembler.h"
28 # include "Parallel.h"
32 #if defined(GRAN) || defined(PAR)
33 # include "GranSimRts.h"
41 /* Hack: we assume that we're building a batch-mode system unless
44 # ifndef INTERPRETER /* Hack */
45 int main(int argc, char *argv[])
48 SchedulerStatus status;
49 /* all GranSim/GUM init is done in startupHaskell; sets IAmMainThread! */
51 startupHaskell(argc,argv);
53 /* kick off the computation by creating the main thread with a pointer
54 to mainIO_closure representing the computation of the overall program;
55 then enter the scheduler with this thread and off we go;
57 the same for GranSim (we have only one instance of this code)
59 in a parallel setup, where we have many instances of this code
60 running on different PEs, we should do this only for the main PE
61 (IAmMainThread is set in startupHaskell)
67 { /* a wait loop to allow attachment of gdb to UNIX threads */
70 for (i=0, s=0; i<(nat)RtsFlags.ParFlags.wait; i++)
71 for (j=0; j<1000000; j++)
75 belch("Passed wait loop"));
78 if (IAmMainThread == rtsTrue) {
79 fprintf(stderr, "Main Thread Started ...\n");
81 /* ToDo: Dump event for the main thread */
82 status = rts_evalIO((StgClosure *)&mainIO_closure, NULL);
84 /* Just to show we're alive */
86 fprintf(stderr, "== [%x] Non-Main PE enters scheduler without work ...\n",
89 /* all non-main threads enter the scheduler without work */
90 status = schedule( /* nothing */ );
95 /* ToDo: Dump event for the main thread */
96 status = rts_evalIO((StgClosure *)&mainIO_closure, NULL);
98 # else /* !PAR && !GRAN */
100 /* ToDo: want to start with a larger stack size */
101 status = rts_evalIO((StgClosure *)&mainIO_closure, NULL);
103 # endif /* !PAR && !GRAN */
105 // ToDo: update for parallel execution
106 /* check the status of the entire Haskell computation */
109 prog_belch("no threads to run: infinite loop or deadlock?");
110 exit_status = EXIT_DEADLOCK;
113 prog_belch("main thread killed");
114 exit_status = EXIT_KILLED;
117 prog_belch("interrupted");
118 exit_status = EXIT_INTERRUPTED;
121 exit_status = EXIT_SUCCESS;
124 barf("main thread completed with invalid status");
126 shutdownHaskellAndExit(exit_status);
128 # endif /* BATCH_MODE */