求救:AIX 4.3上用pthread_create创建线程时居然随机地非法操作?
双CPU的机器。主程序先用setitimer()启动了定时器,然后在SIGALRM信号的处理函数中定时用pthread_create函数创建一个新的线程去处理某些任务。结果发现pthread_create()调用本身会随机地非法操作(即在第X次调用该函数时非法操作)。线程函数在入口处已经用mutex做了同步,防止线程函数重入。
gdb显示出非法操作时的堆栈如下。看起来是pthread_create函数内部在锁定资源时出错。不知如何解决?
Program terminated with signal 11, Segmentation fault.
#0 0xd0019428 in spin_lock_global_ppc_mp ()
(gdb) bt
#0 0xd0019428 in spin_lock_global_ppc_mp ()
#1 0xd0179f88 in __heap_lock ()
#2 0xd017b61c in malloc ()
#3 0xd000a200 in _pthread_alloc ()
#4 0xd000d1e0 in pthread_create ()
#5 0x10000ba8 in _Z15SigAlarmHandleri (signo=14) at main.cpp:111
#6 <signal handler called>
#7 0xd0012908 in _vp_sleep ()
#8 0xd0010fec in _usched_dispatch ()
(gdb)
SIGALRM信号的处理函数如下:
void SigAlarmHandler(int signo)
{
static unsigned long SecondCounter = 0x7FFFFFFF, MinuteCounter = 0x7FFFFFFF;
int ret;
SecondCounter++;
if (SecondCounter >= 10)
{
SecondCounter = 0;
pthread_t tid1;
ret = pthread_create(&tid1, NULL, SendPerfDataProc, NULL);
if(ret)
{
TRACE("can't create SendPerfDataProc thread.\n");
return;
}
ret = pthread_detach(tid1);
}