1 /* -----------------------------------------------------------------------------
2 * $Id: RtsStartup.c,v 1.7 1999/02/11 17:40:27 simonm Exp $
4 * (c) The GHC Team, 1998-1999
6 * Main function for a standalone Haskell program.
8 * ---------------------------------------------------------------------------*/
14 #include "Storage.h" /* initStorage, exitStorage */
15 #include "StablePriv.h" /* initStablePtrTable */
16 #include "Schedule.h" /* initScheduler */
17 #include "Stats.h" /* initStats */
21 #if defined(PROFILING)
24 # include "DebugProf.h"
36 struct RTS_FLAGS RtsFlags;
38 extern void startupHaskell(int argc, char *argv[])
41 int nPEs = 0; /* Number of PEs */
44 /* The very first thing we do is grab the start time...just in case we're
45 * collecting timing statistics.
51 *The parallel system needs to be initialised and synchronised before
54 if (*argv[0] == '-') { /* Look to see whether we're the Main Thread */
55 IAmMainThread = rtsTrue;
56 argv++; argc--; /* Strip off flag argument */
57 /* fprintf(stderr, "I am Main Thread\n"); */
60 * Grab the number of PEs out of the argument vector, and
61 * eliminate it from further argument processing.
66 initEachPEHook(); /* HWL: hook to be execed on each PE */
70 /* Set the RTS flags to default values. */
71 initRtsFlagsDefaults();
73 /* Call the user hook to reset defaults, if present */
76 /* Parse the flags, separating the RTS flags from the programs args */
77 setupRtsFlags(&argc, argv, &rts_argc, rts_argv);
82 /* Initialise the parallel system -- before initHeap! */
84 /* And start GranSim profiling if required: omitted for now
85 *if (Rtsflags.ParFlags.granSimStats)
86 *init_gr_profiling(rts_argc, rts_argv, prog_argc, prog_argv);
90 /* initialize the storage manager */
93 /* initialise the stable pointer table */
96 #if defined(PROFILING) || defined(DEBUG)
100 /* Initialise the scheduler */
103 /* Initialise the stats department */
110 /* Record initialization times */
115 shutdownHaskell(void)
117 /* Finalize any remaining weak pointers */
118 finalizeWeakPointersNow();
122 if (!RTSflags.GranFlags.granSimStats_suppressed)
126 /* clean up things from the storage manager's point of view */
129 #if defined(PROFILING) || defined(DEBUG)
133 #if defined(PROFILING)
134 report_ccs_profiling( );
137 #if defined(TICKY_TICKY)
138 if (RtsFlags.TickyFlags.showTickyStats) PrintTickyInfo();
142 This fflush is important, because: if "main" just returns,
143 then we will end up in pre-supplied exit code that will close
144 streams and flush buffers. In particular we have seen: it
145 will close fd 0 (stdin), then flush fd 1 (stdout), then <who
148 But if you're playing with sockets, that "close fd 0" might
149 suggest to the daemon that all is over, only to be presented
150 with more stuff on "fd 1" at the flush.
152 The fflush avoids this sad possibility.
159 * called from STG-land to exit the program cleanly