Increase ptime under MinGW

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.

+6
source share
1 answer

Check if your code calls gmtime () or gmtime_r () (use a debugger for this). See http://www.boost.org/doc/libs/1_48_0/boost/date_time/c_time.hpp and note that BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS must be defined in order for the time to be thread safe.

+2
source

Source: https://habr.com/ru/post/900266/


All Articles