gpt4 book ai didi

c++ - 如何运行时检查代码是否由给定的 asio::strand 实例保护

转载 作者:太空宇宙 更新时间:2023-11-04 11:35:57 25 4
gpt4 key购买 nike

我想在我的代码中添加一个运行时断言,以检查代码是否受到给定链的保护。

这是一个伪例子:

...

asio::io_service my_io_service;
asio::strand my_strand(my_io_service);

...

void my_async_callback(void) {
// ASSERT that check that my_strand is guarding then code
ASSERT(?? my_strand ??)
}

...

// With this call my_async_callback is guarded by strand
my_strand.post(&my_async_callback);
...

// With this call my_async_callback is NOT guarded by strand
io_service.post(&my_async_callback);

最佳答案

我想你可能正在寻找

 assert(my_strand.running_in_this_thread());

参见 the documentation page

关于c++ - 如何运行时检查代码是否由给定的 asio::strand 实例保护,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23055021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com