【发布时间】:2018-11-26 19:02:47
【问题描述】:
我的代码使用旧版本的 boost 1.49 可以工作,但那是很多年前的事了。现在我正在使用 boost 1.67
编辑:我的项目包含使用相同二进制文件的服务器/客户端功能。 服务器启动后,我可以发送接收到的命令以启动自定义进程。这是下面显示的代码。
我确定了导致内核陷阱的行:
boost::thread th(Temporal::Acquire, transmit, ECONF);
线程正在启动并调用参数中的函数,但启动的线程立即崩溃。 我不明白“一般保护”。
我试图从 try catch (std::exception &e) 中找到更多答案 但它似乎需要另一个捕手...之间没有输出。
试图了解在 libs/thread/src/pthread/thread.cpp 中对 tls_destructor 的处理,但是由于我已经通过将所有 std 替换为 boost 来测试我的代码,但没有解决问题...
Valgrind 没有显示任何错误。
有没有办法理解直接终止(无需调用join或中断)?
使用标准线程启动服务器套接字(来自另一个文件)的部分,但我认为这不是问题的根源: 自从我开始我的项目以来,我从来没有在混合 std / boost 时遇到过冲突。
coex.push_back(std::thread(Temporal::Listener, ECONF));
服务器部分:
#include "lobe.hpp"
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
void Temporal::Acquire(std::string transmit, Json::Value ECONF)
{
syslog(LOG_NOTICE, "aquired");
// Temporal::Transcode p(transmit, ECONF);
}
void Temporal::Listener(Json::Value ECONF)
{
socklen_t t;
std::string transmit(100, 0);
int PIPE_local, PIPE_remote, len;
struct sockaddr_un local, remote;
int reuseaddr = 1;
memset(&local, 0, sizeof(local));
if((PIPE_local = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
perror("socket");
if(setsockopt(PIPE_local, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(reuseaddr)) == -1)
perror(strerror(errno));
local.sun_family = AF_UNIX;
strncpy(local.sun_path, P_SOCK, sizeof(local.sun_path)-1);
unlink(P_SOCK);
len = strlen(local.sun_path) + sizeof(local.sun_family);
if(bind(PIPE_local, (struct sockaddr *)&local, len) == -1)
perror("bind");
if(listen(PIPE_local, 5) == -1)
perror("listen");
for(;;)
{
syslog(LOG_INFO, "inside SOCK");
int done, com_Listen, com_Talk;
t = sizeof(remote);
if((PIPE_remote = accept(PIPE_local, (struct sockaddr *)&remote, &t)) == -1)
perror("accept");
done = 0;
do
{
com_Listen = read(PIPE_remote, &transmit[0], 99);
if(com_Listen <= 0)
{
syslog(LOG_NOTICE, "<<-== %s", transmit.c_str());
if(com_Listen < 0) perror("recv");
done = 1;
syslog(LOG_NOTICE, "received");
boost::thread th(Temporal::Acquire, transmit, ECONF);
}
}while(!done);
close(PIPE_remote);
break;
}
close(PIPE_local);
unlink(P_SOCK);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
//boost::this_thread::sleep_for(boost::chrono::seconds(1));
Temporal::Listener(ECONF);
}
客户端部分:
systemd coredump 的输出:
Jun 17 22:37:25 bytewild kernel: traps: EIE[8033] general protection ip:44f59c sp:7fd32bffecb0 error:0 in EIE[400000+233000]
Jun 17 22:37:25 bytewild EIE[7699]: aquired
Jun 17 22:37:25 bytewild systemd[1]: Started Process Core Dump (PID 8034/UID 0).
-- Subject: Unit systemd-coredump@49-8034-0.service has finished start-up
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Unit systemd-coredump@49-8034-0.service has finished starting up.
--
-- The start-up result is RESULT.
Jun 17 22:37:25 bytewild systemd-coredump[8041]: Failed to get ACL: Operation not supported
Jun 17 22:37:26 bytewild systemd-coredump[8041]: Process 7699 (EIE) of user 1000 dumped core.
Stack trace of thread 8033:
#0 0x000000000044f59c tls_destructor (/data/dev/in/native/projects/eie/build/bin/EIE)
#1 0x000000000045092a thread_proxy (/data/dev/in/native/projects/eie/build/bin/EIE)
#2 0x0000000000500155 start_thread (/data/dev/in/native/projects/eie/build/bin/EIE)
#3 0x00000000005707ff __clone (/data/dev/in/native/projects/eie/build/bin/EIE)
Stack trace of thread 7700:
#0 0x0000000000503623 __pthread_cond_timedwait (/data/dev/in/native/projects/eie/build/bin/EIE)
#1 0x000000000041214b _ZN5boost18condition_variable13do_wait_untilERNS_11unique_lockINS_5mutexEEERKNS_6detail23mono_platform_timepointE (/data/dev/in/native/projects/eie/build/bin/EIE)
#2 0x000000000040ebe4 _ZN8Temporal8ListenerEN4Json5ValueE (/data/dev/in/native/projects/eie/build/bin/EIE)
#3 0x000000000041f58e _ZSt13__invoke_implIvPFvN4Json5ValueEEJS1_EET_St14__invoke_otherOT0_DpOT1_ (/data/dev/in/native/projects/eie/build/bin/EIE)
#4 0x00000000004eb0ef execute_native_thread_routine (/data/dev/in/native/projects/eie/build/bin/EIE)
#5 0x0000000000500155 start_thread (/data/dev/in/native/projects/eie/build/bin/EIE)
#6 0x00000000005707ff __clone (/data/dev/in/native/projects/eie/build/bin/EIE)
Stack trace of thread 7699:
#0 0x0000000000504a21 __nanosleep (/data/dev/in/native/projects/eie/build/bin/EIE)
#1 0x000000000056bfea __sleep (/data/dev/in/native/projects/eie/build/bin/EIE)
#2 0x0000000000406e91 main (/data/dev/in/native/projects/eie/build/bin/EIE)
#3 0x0000000000506dfa __libc_start_main (/data/dev/in/native/projects/eie/build/bin/EIE)
#4 0x000000000040790a _start (/data/dev/in/native/projects/eie/build/bin/EIE)
这是我的系统的示意图预览,以了解问题:
对不起,如果这很明显,但我很难过。有什么线索吗?
【问题讨论】:
-
我看到你的线程是在块的末尾创建的。看这个,似乎线程在完成工作之前就被破坏了。如果您在创建线程后分离线程。它解决了您的异常问题吗?
-
嗨,Feddy,你说得对,我认为是这样,但添加 th.detach() 并不能解决问题。我刚刚更新了我的帖子,以解释我对项目的更多期望。
标签: c++ boost-thread coredump