1 /* -----------------------------------------------------------------------------
2 * $Id: Main.c,v 1.18 2000/03/14 09:55:05 simonmar 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"
29 # include "Parallel.h"
33 #if defined(GRAN) || defined(PAR)
34 # include "GranSimRts.h"
42 /* Hack: we assume that we're building a batch-mode system unless
45 # ifndef INTERPRETER /* Hack */
46 int main(int argc, char *argv[])
49 SchedulerStatus status;
50 /* all GranSim/GUM init is done in startupHaskell; sets IAmMainThread! */
52 startupHaskell(argc,argv);
54 /* kick off the computation by creating the main thread with a pointer
55 to mainIO_closure representing the computation of the overall program;
56 then enter the scheduler with this thread and off we go;
58 the same for GranSim (we have only one instance of this code)
60 in a parallel setup, where we have many instances of this code
61 running on different PEs, we should do this only for the main PE
62 (IAmMainThread is set in startupHaskell)
68 { /* a wait loop to allow attachment of gdb to UNIX threads */
71 for (i=0, s=0; i<(nat)RtsFlags.ParFlags.wait; i++)
72 for (j=0; j<1000000; j++)
76 belch("Passed wait loop"));
79 if (IAmMainThread == rtsTrue) {
80 fprintf(stderr, "Main Thread Started ...\n");
82 /* ToDo: Dump event for the main thread */
83 status = rts_evalIO(mainIO_closure, NULL);
85 /* Just to show we're alive */
87 fprintf(stderr, "== [%x] Non-Main PE enters scheduler without work ...\n",
90 /* all non-main threads enter the scheduler without work */
91 status = schedule( /* nothing */ );
96 /* ToDo: Dump event for the main thread */
97 status = rts_evalIO(mainIO_closure, NULL);
99 # else /* !PAR && !GRAN */
101 /* ToDo: want to start with a larger stack size */
102 status = rts_evalIO((StgClosure *)mainIO_closure, NULL);
104 # endif /* !PAR && !GRAN */
106 // ToDo: update for parallel execution
107 /* check the status of the entire Haskell computation */
110 prog_belch("no threads to run: infinite loop or deadlock?");
111 exit_status = EXIT_DEADLOCK;
114 prog_belch("main thread killed");
115 exit_status = EXIT_KILLED;
118 prog_belch("interrupted");
119 exit_status = EXIT_INTERRUPTED;
122 exit_status = EXIT_SUCCESS;
125 barf("main thread completed with invalid status");
127 shutdownHaskellAndExit(exit_status);
129 # endif /* BATCH_MODE */