Sept. 22, 2014
5:48 a.m.
Andy Heninger wrote:
If it were up to me, I would probably remove use of the double-checked idiom, and rely on solely lock(). Slightly slower, but simple, portable and safe.
Thanks very much for the review. Your suggestion makes gmtime 13% slower on my platform (Fedora 20 x86-64) when THREAD_SAFE is defined, due to the locking overhead, but safe is better than potentially-buggy. Attached are three proposed patches that should address the problems you raise. Patch 1 fixes the memory leak race in gmtcheck. Patch 2 should port to the C11 memory model. Patch 3 should work around the resulting gmtime slowdown in zdump by having zdump use localtime_rz instead of gmtime to convert time stamps to UTC.