Chrono crypto

Comment

Author: Admin | 2025-04-28

Given the following code:#include #include #include #include #include #include #include #include #include #include class Async{public: Async() = default; Async(const Async&) = delete; Async(Async&&) = delete; ~Async() = default; //{ m_mutex.unlock(); } Async& operator=(const Async&) = delete; Async& operator=(Async&&) = delete; template QFuture operator()( std::function&& p_function, std::chrono::milliseconds p_timeout, t_result* p_result) { QtConcurrent::run([this, p_function, p_result]() { *p_result = p_function(); std::cout (p_timeout.count())); std::cout f1 = []() -> char { std::this_thread::sleep_for(std::chrono::seconds(4)); return 'a'; }; std::cout result = async(std::move(f1), std::chrono::milliseconds(3999), &letter); std::cout Finally... 8), when I run it, all the cout print what is expected, but I get a QMutex: destroying locked mutex at the end of the execution. Since I am getting the message finished waiting, the m_cond.wait is executed, therefore (I thought), m_mutex would be unlocked. But it does not seem so. If I use ~Async() { m_mutex.unlock(); }, I do not get the message, but I do not think it should be done this way.Could anyone, please, explain why the mutex is not being released?Thanks a lot!

Add Comment