上程序:
最后出来的结果是:
21:18:39
21:18:39
和最初想法不一致。
查阅localtime的文档,发现这段话:
This structure is statically allocated and shared by the functions gmtime and localtime. Each time either one of these functions is called the content of this structure is overwritten.
也就是说每次只能同时使用localtime()函数一次,要不就会被重写!
The localtime() function need not be reentrant. A function that is not required to be reentrant is not required to be thread-safe.
因此localtime()不是可重入的。同时libc里提供了一个可重入版的函数localtime_r();
Unlike localtime(), the reentrant version is not required to set tzname。
修改程序:
最后出来的结果是:
10:29:06
10:59:06