localtime_r在多线程环境下可能存在死锁
来源:互联网 发布:怎么在origin显示数据 编辑:程序博客网 时间:2024/05/22 00:31
localtime_r是localtime的线程安全版本,在localtime的手册中描述如下:
Attention: Do not use the ctime, localtime, gmtime, or asctime subroutine in a multithreaded
environment. See the multithread alternatives in the ctime_r (ctime_r,localtime_r, gmtime_r, or
asctime_r Subroutine), localtime_r, gmtime_r, or asctime_r subroutine article.
#include <pthread.h>
#include <time.h>
void *mytest(void *arg)
{
pthread_detach(pthread_self());
time_t current;
struct tm date;
time(¤t);
while (1) {
localtime_r(¤t, &date);
printf("OK/n");
}
}
int main()
{
int i = 0;
pthread_t tid[10];
for (i = 0; i < 10; i++) {
pthread_create(&tid[i], NULL, mytest, NULL);
}
sleep(1);
pthread_cancel(tid[0]);
pthread_cancel(tid[1]);
pthread_cancel(tid[2]);
pthread_cancel(tid[3]);
while (1)
sleep(100000000);
}
(dbx) thread
thread state-k wchan state-u k-tid mode held scope function
$t1 wait 0xf100060027c244b0 running 7172309 k no sys nsleep
*$t2 run blocked 7176385 k no sys _global_lock_common
$t3 wait 0x000000011000ad18 blocked 3379347 k no sys _rec_mutex_lock
$t4 zomb terminated 7180483 k no sys pthread_exit
$t5 wait 0x000000011000ad18 blocked 9109677 k no sys _rec_mutex_lock
>$t6 wait 0x000000011000ad18 blocked 3498171 k no sys _rec_mutex_lock
$t7 wait 0x000000011000ad18 blocked 3502269 k no sys _rec_mutex_lock
$t8 wait 0x000000011000ad18 blocked 3506367 k no sys _rec_mutex_lock
$t9 wait 0x000000011000ad18 blocked 2384027 k no sys _rec_mutex_lock
$t10 wait 0x000000011000ad18 blocked 2932903 k no sys _rec_mutex_lock
$t11 wait 0x000000011000ad18 blocked 2494699 k no sys _rec_mutex_lock
(dbx) where
_rec_mutex_lock(??) at 0x900000000028f90
localtime_tz_r(??, ??, ??) at 0x900000000055644
mytest(0x0) at 0x1000005fc
所有的线程都在试图获取锁,进程处于死锁状态。目前AIX工程师给出的临时解决方案是将环境变量TZ设置为BEIST,
export TZ=BEIST
之后再运行测试程序就没有死锁的现象。由于TZ是一个系统环境变量,修改之后可能会引起其他系统出问题.
- localtime_r在多线程环境下可能存在死锁
- localtime_r在多线程环境下可能存在死锁
- mktime和localtime_r能在多线程环境下使用么?
- 多线程情况下慎用localtime_r
- 【Java 单例模式】Java 单例模式在多线程环境中可能存在的问题
- 多线程环境下定时器存在的问题
- [Golang]Coroutine可能存在的死锁
- 浅谈 Java 多线程环境下 如何跟踪死锁 (例子)
- 多线程共用全局变量可能存在的威胁
- openswan在NAT环境且开启DPD时双方SA生存周期不同可能存在问题
- openswan在NAT环境且开启DPD时双方SA生存周期不同可能存在问题
- logback多线程下死锁问题
- SQLite在多线程环境下的应用
- SQLite在多线程环境下的应用
- SQLite在多线程环境下的应用
- SQLite在多线程环境下的应用
- SQLite在多线程环境下的应用
- SQLite在多线程环境下的应用
- 远程调用对比RMI、MINA、ESB、Burlap、Hessian、SOAP、EJB和JMS
- 常用stl 容器用法
- Struts2的数据校验
- sql别名何时使用
- MySQL数据库备份命令
- localtime_r在多线程环境下可能存在死锁
- Java内部类的使用小结
- RSA实践指南
- Soluton for Exception:FND_SOA_SERVICE_EXECUTION_ERR:oracle.apps.fnd.soa.util.SOAException
- ORA-39006/39213错误
- ORACLE_触发器
- WinCE注册表操作API
- scrollLeft、offsetLeft、clientLeft、clientHeight详解
- CSting与char int sting的转换