在“CefExecuteProcess”之前创建新线程会导致 CEF 应用程序因 SIGTRAP 崩溃

问题描述 投票:0回答:1

我使用以下代码启动我的 CEF 申请

void EmtpyThreadFunc()
{
    // create one infinite loop thread to keep the process alive
    while (true)
    {
        sleep(1000);
    }
}


int main(int argc, char* argv[])
{
    std::string name = "MyTestProject";
    //std::thread sampleThread(EmtpyThreadFunc); // Enabling this causes the program to crash

     // Parse command-line arguments.
    auto commandLine = CefCommandLine::CreateCommandLine();
    commandLine->InitFromArgv(argc, argv);

    // Create a ClientApp of the correct type.
    CefRefPtr<CefApp> app;

    /* code to initialize app is removed */
    

    CefMainArgs args(argc, argv);

    // Execute the secondary process, if any.
    int exitCode = CefExecuteProcess(args, app, NULL);
    if (exitCode >= 0)
    {
        return exitCode;
    }

    // rest of codes

}

启用

sampleThread
除了运行无限 while 循环之外什么也不做,导致我的 CEF 应用程序以 SIGTRAP 退出。

堆栈如下所示

Program terminated with signal SIGTRAP, Trace/breakpoint trap.
#0  0x00007f207dc82b02 in operator() () at ../../services/service_manager/zygote/zygote_main_linux.cc:161
161     ../../services/service_manager/zygote/zygote_main_linux.cc: No such file or directory.
[Current thread is 1 (Thread 0x7f2075d31d80 (LWP 86988))]
(gdb) bt
#0  0x00007f207dc82b02 in operator() () at ../../services/service_manager/zygote/zygote_main_linux.cc:161
#1  EnterLayerOneSandbox () at ../../services/service_manager/zygote/zygote_main_linux.cc:161
#2  ZygoteMain () at ../../services/service_manager/zygote/zygote_main_linux.cc:222
#3  0x00007f207c06748c in RunZygote () at ../../content/app/content_main_runner_impl.cc:471
#4  0x00007f207c068791 in Run () at ../../content/app/content_main_runner_impl.cc:876
#5  0x00007f207dc8383a in MainRun () at ../../services/service_manager/embedder/main.cc:430
#6  0x00007f207dc83d0e in Main () at ../../services/service_manager/embedder/main.cc:477
#7  0x00007f207c066cf1 in content::ContentMain(content::ContentMainParams const&) () at ../../content/app/content_main.cc:19
#8  0x00007f207c29b7a0 in CefExecuteProcess () at ../../cef/libcef/browser/context.cc:220
#9  0x00007f2079f6b6da in cef_execute_process () at ../../cef/libcef_dll/libcef_dll.cc:78
#10 0x00005602a0a53984 in CefExecuteProcess(CefMainArgs const&, scoped_refptr<CefApp>, void*) ()

我在 Linux 中使用 CEF 81.2.16,在 CEF 121 上也看到了几乎相同的问题。 使用以下命令行参数。

--no-sandbox  --x=0 --y=0 --width=1281 --height=801 --disable-pinch --disable-web-security --log-severity=disable --ignore-certificate-errors --showDevTools
c++ linux multithreading chromium-embedded
1个回答
0
投票

沙箱初始化要求沙箱前代码中不得生成其他线程。

--no-sandbox
不会禁用此要求。您不能在调用
CefExecuteProcess()
之前创建线程。

© www.soinside.com 2019 - 2024. All rights reserved.