Search code examples
c++linuxlinux-kernelpthreadsdaemon

Return a function while daemon thread is working in the background (c++)


I want to return function 'A' with some return value(let's say '0') while a daemon thread started running inside this function but may not finished. Is that even possible?


Solution

  • Just detach the thread and then return from the function.

    int createThreadAndReturn() {
        std::thread(daemon_thread_function).detach();
        return 0;
    }