2

我们创建了一个在 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
4

2 回答 2

3

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

于 2014-10-01T13:01:25.903 回答
0

根据Syed AslamACE_Thread::spawn_n的报告,使用默认使用的 ACE C++ 版本 6.5.1 库类在调用内部子级ACE_DEFAULT_THREAD_PRIORITY (1024*1024)时会崩溃。libxml2 模式解析需要永远,使用子线程 Segment Faulted after call as it try to resolve 。gethostbyname/getaddrinfoxmlNanoHTTPConnectHostschemaLocation

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
);
于 2019-04-10T19:42:58.433 回答