just brew it! wrote:johnrreagan wrote:On our platform (OpenVMS), our ctime() implementation actually allocates a mutex-locked, thread-specific buffer and then calls ctime_r() effectively deprecating ctime().
Why is a mutex needed when the buffer is thread-specific? That seems overly paranoid to me, and could even result in deadlocks if ctime() is used from a signal handler.
I was thinking the same thing. Plus the fact that a mutex can be very expensive. Lock-free methods might be better here, if possible.
On the other hand, lock-free coding is much more complex to reason about, so just going with the mutex is generally less buggy, even if slower.