1 /* -----------------------------------------------------------------------------
2 * $Id: RtsStartup.c,v 1.2 1998/12/02 13:28:41 simonm Exp $
4 * Main function for a standalone Haskell program.
6 * ---------------------------------------------------------------------------*/
12 #include "Storage.h" /* initStorage, exitStorage */
13 #include "StablePtr.h" /* initStablePtrTable */
14 #include "Schedule.h" /* initScheduler */
15 #include "Stats.h" /* initStats */
18 #if defined(PROFILING)
21 # include "DebugProf.h"
33 struct RTS_FLAGS RtsFlags;
35 extern void startupHaskell(int argc, char *argv[])
38 int nPEs = 0; /* Number of PEs */
41 /* The very first thing we do is grab the start time...just in case we're
42 * collecting timing statistics.
48 *The parallel system needs to be initialised and synchronised before
51 if (*argv[0] == '-') { /* Look to see whether we're the Main Thread */
52 IAmMainThread = rtsTrue;
53 argv++; argc--; /* Strip off flag argument */
54 /* fprintf(stderr, "I am Main Thread\n"); */
57 * Grab the number of PEs out of the argument vector, and
58 * eliminate it from further argument processing.
63 initEachPEHook(); /* HWL: hook to be execed on each PE */
67 /* Set the RTS flags to default values. */
68 initRtsFlagsDefaults();
70 /* Call the user hook to reset defaults, if present */
73 /* Parse the flags, separating the RTS flags from the programs args */
74 setupRtsFlags(&argc, argv, &rts_argc, rts_argv);
79 /* Initialise the parallel system -- before initHeap! */
81 /* And start GranSim profiling if required: omitted for now
82 *if (Rtsflags.ParFlags.granSimStats)
83 *init_gr_profiling(rts_argc, rts_argv, prog_argc, prog_argv);
87 /* initialize the storage manager */
90 /* initialise the stable pointer table */
93 #if defined(PROFILING) || defined(DEBUG)
97 /* Initialise the scheduler */
100 /* Initialise the stats department */
107 /* Record initialization times */
112 shutdownHaskell(void)
114 /* Finalise any remaining weak pointers */
115 finaliseWeakPointersNow();
119 if (!RTSflags.GranFlags.granSimStats_suppressed)
123 /* clean up things from the storage manager's point of view */
126 #if defined(PROFILING) || defined(DEBUG)
130 #if defined(PROFILING)
131 report_ccs_profiling( );
134 #if defined(TICKY_TICKY)
136 if (RTSflags.TickyFlags.showTickyStats) PrintTickyInfo();
140 This fflush is important, because: if "main" just returns,
141 then we will end up in pre-supplied exit code that will close
142 streams and flush buffers. In particular we have seen: it
143 will close fd 0 (stdin), then flush fd 1 (stdout), then <who
146 But if you're playing with sockets, that "close fd 0" might
147 suggest to the daemon that all is over, only to be presented
148 with more stuff on "fd 1" at the flush.
150 The fflush avoids this sad possibility.
157 * called from STG-land to exit the program cleanly