- 论坛徽章:
- 0
|
#include <pthread.h>
#include <time.h>
void test(char *arg)
{
pthread_detach(pthread_self());
struct tm now;
time_t datetime;
while (1) {
time (&datetime);
localtime_r(&datetime, &now);
usleep(10);
}
}
int main()
{
int rt;
int tid[7];
pthread_create(&tid[0], NULL, test, NULL);
pthread_create(&tid[1], NULL, test, NULL);
pthread_create(&tid[2], NULL, test, NULL);
pthread_create(&tid[3], NULL, test, NULL);
pthread_create(&tid[4], NULL, test, NULL);
pthread_create(&tid[5], NULL, test, NULL);
pthread_create(&tid[6], NULL, test, NULL);
usleep(3000);
pthread_cancel(tid[0]);
pthread_cancel(tid[1]);
pthread_cancel(tid[2]);
pthread_cancel(tid[3]);
sleep(1000000);
}
运行大概2秒左右,使用dbx得到如下结果:
(dbx) thread
thread state-k wchan state-u k-tid mode held scope function
$t1 wait 0xf1000610124a19b0 running 16978061 k no sys nsleep
$t2 zomb terminated 13464059 k no sys pthread_exit
>$t3 run blocked 21594345 k no sys _global_lock_common
$t4 wait 0x000000011000abb8 blocked 21369113 k no sys _rec_mutex_lock
$t5 wait 0x000000011000abb8 blocked 17006771 k no sys _rec_mutex_lock
$t6 wait 0x000000011000abb8 blocked 21324271 k no sys _rec_mutex_lock
$t7 wait 0x000000011000abb8 blocked 21598443 k no sys _rec_mutex_lock
$t8 wait 0x000000011000abb8 blocked 21332225 k no sys _rec_mutex_lock
使用truss命令检查,进程一直停在sleep。没有任何localtime_r的函数调用。
我的环境是AIX6.1,目前没有其他的环境,无法进行测试,能帮忙解释一下原因吗?谢谢! |
|