簡體   English   中英

應用程序背景時線程被殺死了嗎?

[英]Thread killed when application is backgrounded?

我正在開發一個fuse文件系統,在調用fuse_main_real()之前,我正在類實例中啟動一個std::thread來做一些后台工作。

this->t_receive = new std::thread([this] { this->receive(); });

但是,在進入后台時,似乎fuse_main_real()殺死此線程。
如果我使用-f選項啟動程序,它告訴fuse保持在前台,問題不會發生並且線程仍然存在。

我不確定什么保險絲會進入后台。

如何使我的線程在后台生存?


編輯:這是一個暴露問題的基本示例:

#define FUSE_USE_VERSION 30

#include <iostream>
#include <thread>

#include <fuse.h>

static void thread_method()
{
        while (true)
        {
                std::cout << "test" << std::endl;
                std::this_thread::sleep_for(std::chrono::seconds(1));
        }
}

struct testop : fuse_operations
{ };

static struct testop ops;

int main(int argc, char** argv)
{
        std::thread(thread_method).detach();
        fuse_main_real(argc, argv, &ops, sizeof(fuse_operations), NULL);
}

編譯

g++ -D_FILE_OFFSET_BITS=64 `pkg-config --cflags fuse` -lfuse -lpthread -std=c++14 -o test.o test.cpp

有效的命令(反復說“測試”):

./test.o -f /home/test/testmountpoint

命令不起作用並顯示問題(說“test”一次):

./test.o /home/test/testmountpoint

libfuse維基

應該從init()方法啟動其他線程。 當進程進入后台時,fuse_main()將退出之前啟動的線程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM