- 論壇徽章:
- 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的函數(shù)調用。
我的環(huán)境是AIX6.1,目前沒有其他的環(huán)境,無法進行測試,能幫忙解釋一下原因嗎?謝謝! |
|