从子线程调用时,getaddrinfo和gethostbyname崩溃了吗?

时间:2014-09-26 15:38:26

标签: c linux multithreading getaddrinfo gethostbyname

我们已经创建了一个在Ubuntu上运行的多线程单核应用程序。

当我们从主进程中调用getaddrinfogethostbyname时,它不会崩溃。

但是,当我们从主进程创建一个线程并且从创建的线程调用函数getaddrinfogethostbyname时,它总是崩溃。

请帮助。 请在下面找到调用堆栈:

#0  0xf7e9f890 in ?? () from /lib/i386-linux-gnu/libc.so.6
#1  0xf7e9fa73 in __res_ninit () from /lib/i386-linux-gnu/libc.so.6
#2  0xf7ea0a68 in __res_maybe_init () from /lib/i386-linux-gnu/libc.so.6
#3  0xf7e663be in ?? () from /lib/i386-linux-gnu/libc.so.6
#4  0xf7e696bb in getaddrinfo () from /lib/i386-linux-gnu/libc.so.6
#5  0x080c4e35 in mn_task_entry (args=0xa6c4130 <ipc_os_input_params>) at /home/nextg/Alps_RT/mn/src/mn_main.c:699
#6  0xf7fa5d78 in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#7  0xf7e9001e in clone () from /lib/i386-linux-gnu/libc.so.6

2 个答案:

答案 0 :(得分:2)

getaddrinfo崩溃的原因是,进行调用的子线程没有足够的堆栈空间。

答案 1 :(得分:0)

根据 Syed Aslam 报告,在子对象内部调用ACE_Thread::spawn_n时,使用使用ACE_DEFAULT_THREAD_PRIORITY (1024*1024)和默认gethostbyname/getaddrinfo的ACE C ++版本6.5.1库类将崩溃。调用xmlNanoHTTPConnectHost后,它尝试解析schemaLocation时,使用子线程Segment Faulted来进行libxml2模式解析,这是永远的事。

ACE_Task激活

const ACE_TCHAR *thr_name[1];
thr_name[0] = "Flerf";
// libxml2-2.9.7/nanohttp.c:1133
// gethostbyname will crash when child thread making the call 
// has insufficient stack space.
size_t stack_sizes[1] = {
  ACE_DEFAULT_THREAD_STACKSIZE * 100
};

const INT ret = this->activate (
  THR_NEW_LWP/*Light Weight Process*/ | THR_JOINABLE,
  1,
  0/*force_active*/,
  ACE_DEFAULT_THREAD_PRIORITY,
  -1/*grp_id*/,
  NULL/*task*/,
  NULL/*thread_handles[]*/,
  NULL/*stack[]*/,
  stack_sizes/*stack_size[]*/,
  NULL/*thread_ids[]*/,
  thr_name
);