Question: ANSI C time function are not thread safe: in particular `gmtime`, `ctime` and `strftime`. For what I know the only thread-safe function is `time`.

If I'm right in Visual Studio this function are all thread safe. I'm using MinGW compiler (4.8.0 with dwarf-2, that one provided by Qt 5.1.0 ).

How can inplement thread safe function of `gmtime_r`, `ctime_r` and `strftime_r`? Or is there a more thread-safe library for that?

I'm using C++11 as default language.

 **edit 1**   

I'm using MinGW 4.8.0 (posix, dwarf-2) on windows xp.

 **edit 2**   

I'm considering to use Boost.DateTime may it be a good choice?

I'm very disappointed for the lack on c++11 of time managment!

Answer: 
There actually should be `gmtime_r` and `ctime_r` in `pthread.h` but they are temporary removed because of a bug (<http://sourceforge.net/p/mingw/bugs/1625/>).

You have few choices

1. Wait until it will be fixed
2. Use older version of MiniGW
3. Make a reentrant wrapper for all of those functions using `lock_guard` just like `safe_increment` has done [here](http://en.cppreference.com/w/cpp/thread/lock_guard)
4. And maybe best way is to use functions form `chrono` header file added by C++11
MinGW arleady provide both gmtime\_r and gmtime\_s function, but they are note in the `std` namespace.