I have a problem with boost library. I am using MinGW with gcc 4.5.2 to compile the following code:
unsigned long GetEpochSeconds() { using namespace boost::posix_time; using namespace boost::gregorian; ptime now(second_clock::universal_time()); ptime epoch(date(1970,1,1)); time_duration diff = now-epoch; return diff.total_seconds(); }
The problem is that this code is not thread safe. When I run it from multiple threads, my application crashes. At the moment, I have converted to c-standard functions such as time, mktime, etc., and everything works fine, but in the future I will need several acceleration functions.
I also compiled with -D_REENTRANT, but that didn't help.
Thanks for any suggestions.
source share