- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在创建 SSL 套接字,当我尝试连接到该套接字时,我的程序挂起。
我发现一些问题,服务器不发送任何数据,因此 SSL 连接正在等待任何响应。
我决定创建 future 并在超时后将其杀死。但它仍然挂着。
如果您查看代码,下面的部分不会执行:cout<<"TEST";
{
std::future<void> future = std::async(std::launch::async,
[&](){
err = SSL_connect (m_ssl);
});
std::future_status status;
status = future.wait_for(std::chrono::seconds(t_timeout));
}
cout<<"TEST";
为了模拟来自服务器的停止响应,我刚刚运行:
for item in $(seq 1 1000); do sudo nc -i 100000ms -l 443 >> log.out; done;
如何终止 SSL 连接?我想在杀死 future 后继续执行代码。
编辑:我不想为此提出另一个问题。回答:所以我现在确定这是因为 future 的析构函数。它正在等待来自 future 主体的代码完成。
问题 2:我该如何解决上述问题?我想在 future 所在的范围之后执行代码。
是否可以创建线程并等待超时或 ssl 某些互斥体被解锁?
最佳答案
您的代码的问题在于,当 future 超出范围时,它的析构函数可能会阻塞,如 documentation 中所报告的那样对于 std::future<T>::~future
:
它明确地说:
... will not block for the shared state to become ready, except that it may block if all of the following are true: the shared state was created by a call to std::async, the shared state is not yet ready, and this was the last reference to the shared state.
在你的情况下:
您的问题的解决方案是您必须使变量的范围为 std::future<void> future
这样它就比您不希望被阻止的代码部分长。
检查这些答案:
关于c++ - std::future.wait_for 永远阻塞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57291078/
我想要一个线程 (std::thread) 每 60 秒完成一次工作,否则休眠并在外部请求时立即返回。std::jthread 不是一个选项,我仅限于 C++14。 std::condition_va
我正在通过 Terraform 配置一个新服务器,并使用 Ansible 作为本地系统上的配置程序。 Terraform 在 EC2 上配置一个系统,然后运行 Ansible playbook,提
我想要一个线程 (std::thread) 每 60 秒完成一次工作,否则休眠并在外部请求时立即返回。std::jthread 不是一个选项,我仅限于 C++14。 std::condition_va
在我的工作环境中,创建了虚拟机,并在创建登录访问信息后将其添加到虚拟机中,这可能会有延迟,所以仅仅等待我的 ansible 脚本检查 SSH 是否可用是不够的,我实际上需要检查是否ansible 可以
假设一个类似这样的命令: @bot.command() async def test(ctx): def check(r, u): return u == ctx.messag
使用 Python 3.6.8 async def sleeper(): time.sleep(2) async def asyncio_sleeper(): await asynci
我正在Visual Studio 2019上使用condition_variable。condition_variable.wait_for()函数将返回std::cv_status::no_time
如果我在文件上使用 search_regex='foo',则使用 Ansible 中的 wait_for 模块 它似乎从文件的开头开始,这意味着它将匹配旧数据,因此当重新启动附加到文件而不是启动新文件
我正在尝试利用队列模块的wait_for方法。我有一个谓词的可调用对象,如果我不传递任何参数,它就可以工作,但是可调用对象需要一个 int 参数。 作品: self.cv.wait_for(fn, t
文档说可以使用 Predicate 的第二次重载来避免虚假唤醒。我没有看到它,如何修改我的代码以确保 wait_for 不会被虚假唤醒? while(count_ > 0) { if (con
我试图测试一批连接,但所有错误响应失败的连接都是“超时”,但我知道(我测试过)其中一些是“没有主机路由”。我如何在 ansible 中使用 wait_for 来做到这一点? - name: Test
我在单元测试中有一些代码等待我的 vector 足够大: bool waitForOutwardMessages(size_t size, int millis) { std::unique_
我正在尝试使用 ansible 来配置我必须使用的环境。特别是,我需要编写一个重启服务器的任务,所以我写了这个任务: - name: waiting for server to come back
Spurious wakup各种平台都允许。为了解决这个问题,我们编写了以下循环机制: while(ContinueWaiting()) cv.wait(lock); // cv is a `
这是来自 http://www.cplusplus.com/reference/condition_variable/condition_variable/wait_for/ 的简单代码 为什么如果我
我无法理解为什么我认为应该通过的测试用例大部分时间都失败了。我已将测试提炼为条件变量并使用 wait_for 方法,具体测试它是否确实至少等待了指定的持续时间。 测试代码片段如下: TEST_CASE
我有C#编码经验;我开始学习 C++ 并使用 boost 库进行线程处理。我编写了以下类 - 试图将成员函数作为线程执行。编写以下简单代码,我希望线程函数内的 while 循环每秒执行一次。 #inc
我正在尝试制作多线程应用程序,其中每个线程都将在不同的时间处理任务。所以我想使用 future 和 future::wait_for 函数。但是当我只使用来自 CPP reference 的代码时 #
条件变量的典型用法如下所示(参见下面的代码):http://en.cppreference.com/w/cpp/thread/condition_variable . 但是,似乎主线程可能会在工作线程
下面是一个运行两个后台任务的简单异步循环。 它们都执行简单的计数。第一个永远重要,包裹在尝试/除外。第二个数到 5,然后取消第一个,停止循环。 有两种方法可以确保取消完成 - asyncio.wait
我是一名优秀的程序员,十分优秀!