Revision 68da4f12

View differences:

include/csimulation.h
126 126

  
127 127
    cStopWatch sequentialWatch;
128 128

  
129
    bool endSimulation;     // used to signal shutdown from threaded context
130

  
129 131
  private:
130 132
    // internal
131 133
    void checkActive()  {if (getActiveSimulation()!=this) throw cRuntimeError(this, eWRONGSIM);}
......
389 391
     * all modules and deleting the messages in the scheduled-event list.
390 392
     */
391 393
    void deleteNetwork();
394

  
395
    /**
396
     * signal shutdown from thread
397
     */
398
    void signalShutdown()  { endSimulation = true; }
392 399
    //@}
393 400

  
394 401
    /** @name Information about the current simulation run. */
src/envir/envirbase.cc
106 106
Register_GlobalConfigOption(CFGID_PRINT_UNDISPOSED, "print-undisposed", CFG_BOOL, "true", "Whether to report objects left (that is, not deallocated by simple module destructors) after network cleanup.");
107 107
Register_GlobalConfigOption(CFGID_SIMTIME_SCALE, "simtime-scale", CFG_INT, "-12", "Sets the scale exponent, and thus the resolution of time for the 64-bit fixed-point simulation time representation. Accepted values are -18..0; for example, -6 selects microsecond resolution. -12 means picosecond resolution, with a maximum simtime of ~110 days.");
108 108
Register_GlobalConfigOption(CFGID_NED_PATH, "ned-path", CFG_PATH, "", "A semicolon-separated list of directories. The directories will be regarded as roots of the NED package hierarchy, and all NED files will be loaded from their subdirectory trees. This option is normally left empty, as the OMNeT++ IDE sets the NED path automatically, and for simulations started outside the IDE it is more convenient to specify it via a command-line option or the NEDPATH environment variable.");
109
Register_GlobalConfigOption(CFGID_WRITE_RUNTIME_TO_FILE, "write-runtime-to-file", CFG_BOOL, "false", "Enables or disables writing of the simulation runtime to file.");
110
Register_GlobalConfigOption(CFGID_WRITE_RUNTIME_TO_FILENAME, "write-runtime-to-filename", CFG_STRING, "runtimes.dat", "Defines the name of the file in which the runtimes are stored.");
109 111

  
110 112
Register_PerRunConfigOption(CFGID_NETWORK, "network", CFG_STRING, NULL, "The name of the network to be simulated.  The package name can be omitted if the ini file is in the same directory as the NED file that contains the network.");
111 113
Register_PerRunConfigOption(CFGID_WARNINGS, "warnings", CFG_BOOL, "true", "Enables warnings.");
......
1673 1675
    gettimeofday(&simendtime, NULL);
1674 1676
    elapsedtime = elapsedtime + simendtime - laststarted;
1675 1677
    simulatedtime = simulation.getSimTime();
1678

  
1679
    bool storeRuntimes = getConfig()->getAsBool(CFGID_WRITE_RUNTIME_TO_FILE);
1680
    if (storeRuntimes)
1681
    {
1682
        std::string filename = getConfig()->getAsString(CFGID_WRITE_RUNTIME_TO_FILENAME);
1683
        std::ofstream outfile;
1684
        outfile.open(filename.c_str(), std::ios::out | std::ios::app);
1685
        outfile << elapsedtime.tv_sec << "." << (elapsedtime.tv_usec/1000) << endl;
1686
        outfile.close();
1687
    }
1676 1688
}
1677 1689

  
1678 1690
timeval EnvirBase::totalElapsed()
src/sim/csimplemodule.cc
731 731

  
732 732
void cSimpleModule::endSimulation()
733 733
{
734
    throw cTerminationException(eENDSIM);
734
    // throwing an exception from a worker thread is not caught and the simulation
735
    // is not cleanly shut down. Workaround: signal shutdown directly to scheduler
736
    //throw cTerminationException(eENDSIM);
737
    simulation.signalShutdown();
735 738
}
736 739

  
737 740
bool cSimpleModule::snapshot(cObject *object, const char *label)
src/sim/csimulation.cc
75 75

  
76 76

  
77 77
cSimulation::cSimulation(const char *name, cEnvir *env) :
78
                cNamedObject(name, false), isrunning(false)
78
                cNamedObject(name, false), isrunning(false),
79
                endSimulation(false)
79 80
{
80 81
    ASSERT(cStaticFlag::isSet()); // cannot be instantiated as global variable
81 82

  
......
649 650

  
650 651
    try
651 652
    {
653
        // a worker signaled to shutdown the simulation
654
        if(endSimulation)
655
            throw cTerminationException(eENDSIM);
656

  
652 657
        // update the number of events that occur at the same simtime
653 658
        simtime_t currentTime = cThreadPool::getSimTime();
654 659
        if (currentTime < msg->getArrivalTime())
src/sim/cthreadpool.cc
56 56

  
57 57

  
58 58
cThreadPool::cThreadPool() :
59
    		shutdownDone(false)
59
    shutdownDone(false)
60 60
{
61 61
}
62 62

  
......
67 67

  
68 68

  
69 69
static void* startWorker(void* arg)
70
		{
70
{
71 71

  
72 72
	cThreadPool* pool = (cThreadPool*)arg;
73 73
	pool->worker();
74 74
	return NULL;
75
		}
75
}
76 76

  
77 77

  
78 78
void cThreadPool::activate()
......
217 217

  
218 218

  
219 219
cThreadLocalData::cThreadLocalData() :
220
    				defaultOwner(NULL)
220
    defaultOwner(NULL)
221 221
{
222 222

  
223 223
}

Also available in: Unified diff