--------- time/localtime.c 和 time/tzset.c localtime_r中调用了tzset_internal来设置时区,入口参数为always=0,所以理论上只要第一次初次化过了,就不需初始化了。参考下面的代码。 但是由于引入了静态变量is_initialized,在多线程环境下,这种实现代码是有问题的。无法保证并发执行环境下的正确性。 ---- (time/tzset.c) ------- /* Interpret the TZ envariable. */ static void internal_function tzset_internal (always)      int always; { static int is_initialized; register const char *tz; register size_t l; char *tzbuf; unsigned short int hh, mm, ss; unsigned short int whichrule; if (is_initialized && !always)     return; is_initialized = 1; ........... } 但是mktime不是这样的, ---- (time/mktime.c) ------- /* Convert *TP to a time_t value. */ time_t mktime (tp)      struct tm *tp; { #ifdef _LIBC /* POSIX.1 8.1.1 requires that whenever mktime() is called, the      time zone names contained in the external variable `tzname' shall      be set as if the tzset() function had been called. */ __tzset (); #endif return __mktime_internal (tp, my_mktime_localtime_r, &localtime_offset); } 由于_LIBC被定义,所以tzset将每次都被调用,而tzset的代码是这样的 ---- (time/tzset.c) ------- void __tzset (void) { __libc_lock_lock (tzset_lock); tzset_internal (1); if (!__use_tzfile)     {       /* Set `tzname'. */       __tzname[0] = (char *) tz_rules[0].name;       __tzname[1] = (char *) tz_rules[1].name;     } __libc_lock_unlock (tzset_lock); }