Index: osdTime.cpp =================================================================== RCS file: /net/phoebus/epicsmgr/cvsroot/epics/base/src/libCom/osi/os/WIN32/osdTime.cpp,v retrieving revision 1.38.2.7 diff -d -u -b -p -r1.38.2.7 osdTime.cpp --- osdTime.cpp 26 Aug 2008 20:31:09 -0000 1.38.2.7 +++ osdTime.cpp 01 Dec 2008 17:03:03 -0000 @@ -85,7 +85,7 @@ private: epicsTimerNotify::expireStatus expire ( const epicsTime & ); }; -static currentTime * pCurrentTime = 0; +static currentTime * volatile pCurrentTime = 0; static const LONGLONG FILE_TIME_TICKS_PER_SEC = 10000000; static const LONGLONG EPICS_TIME_TICKS_PER_SEC = 1000000000; static const LONGLONG ET_TICKS_PER_FT_TICK = @@ -96,11 +96,13 @@ static const LONGLONG ET_TICKS_PER_FT_TI // static int timeRegister(void) { - pCurrentTime = new currentTime (); - /* Must register with generalTime here since the epicsTimer - * in the PLL ends up calling epicsTime::getCurrent() + /* Register with generalTime first since the epicsTimerQueue started + * by the currentTime() constructor calls epicsTime::getCurrent() in + * its timer thread as it starts up. */ generalTimeCurrentTpRegister("PerfCounter", 150, osdTimeGetCurrent); + + pCurrentTime = new currentTime (); pCurrentTime->startPLL (); return 1; } @@ -111,8 +113,13 @@ static int done = timeRegister(); // static int osdTimeGetCurrent ( epicsTimeStamp *pDest ) { - if ( ! pCurrentTime ) { - return epicsTimeERROR; + while ( ! pCurrentTime ) { + /* A thread has called epicsTime::getCurrent() after this routine + * was registered with generalTime but before pCurrentTime was + * set in timeRegister() above. We know that pCurrentTime will + * be set soon though, so we just wait for it. + */ + Sleep(1); } pCurrentTime->getCurrentTime ( *pDest );