操作环境:solaris 8 现象:程序启动,运行正常,但是运行一段时间之后,r="red">r="red">localtime_r 转换时间就比当前时间要晚16个小时,从而导致程序出现异常 如果是时区的环境变量变化了引起的,在程序启动的时候不就已经确定环境变量了?
by foolishfox - C/C++ - 2011-05-25 10:35:54 阅读(2671) 回复(3)
r="red">r="red">localtime_r和mktime是用来在时间分量和时间秒数之间进行转换的标准c函数。但是线程不安全。 有位大侠提供了两种方法: 1、自己实现mktime和r="red">r="red">localtime_r,但是这样时区的计算是麻烦的,当然也可以不使用时区信息,或者使用固定时区,比如北京时区,这样就简单多了。 2、用pthread的mutex来给mktime和r="red">r="red">localtime_r加锁,但是这样要使用pthread库,移植性不够好。 请问各位大牛有没有更好的方案来使用这两个方法? 另: 那位先生...
-bash-2.05b$ g++ -v
reading specs from /usr/local/lib/gcc/hppa2.0w-hp-hpux11.11/3.4.3/specs
Configured with: ./configure : (reconfigured) ./configure : (reconfigured) ./configure : (reconfigured) ./configure : (reconfigured) ./configure : (reconfigured) ./configure
Thread model: single
gcc version 3.4.3
一个cpp文件中包含这样的代码:
[code]
#include
#include
我在 SUN880 Solaris8上开发了一个多线程程序,使用pthread线程,用 cc 编译器进行编译。 程序的线程结构是这样,主线程启动后创建了4个 pthread 线程,这四个 pthread 线程一直运行,直到进程结束才退出。因为需要在多个线程中同时获取系统时间,所以程序中使用了 localltime_r 函数。各个线程中对 localltime_r 的调用频度很高,每秒平均 200 多次,现在发现这样的问题,程序运行起来后,10几秒很快出现内存访问错误。用dbx查看...
我在 SUN880 Solaris8上开发了一个多线程程序,使用pthread线程,用 cc 编译器进行编译。 程序的线程结构是这样,主线程启动后创建了4个 pthread 线程,这四个 pthread 线程一直运行,直到进程结束才退出。因为需要在多个线程中同时获取系统时间,所以程序中使用了 localltime_r 函数。各个线程中对 localltime_r 的调用频度很高,每秒平均 200 多次,现在发现这样的问题,程序运行起来后,10几秒很快出现内存访问错误。用dbx查看...
我在 SUN880 Solaris8上开发了一个多线程程序,使用pthread线程,用 cc 编译器进行编译。\r\n 程序的线程结构是这样,主线程启动后创建了4个 pthread 线程,这四个 pthread 线程一直运行,直到进程结束才退出。因为需要在多个线程中同时获取系统时间,所以程序中使用了 localltime_r 函数。各个线程中对 localltime_r 的调用频度很高,每秒平均 200 多次,现在发现这样的问题,程序运行起来后,10几秒很快出现内存访问错误。用dbx...
1、Definition and Usage 定义和用法 The r="red">localtime() function returns an array that contains the time components of a Unix timestamp. r="red">localtime()函数的作用是:以数组的形式返回本地时间。 2、Syntax 语法 r="red">localtime(timestamp,is_associative) Parameter参数 Description描述 timestamp Optional. Specifies the date or time to be formatted. If no timestamp is specified, it uses the current local time. 可选参数。...