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

How to runtime-check if code is guarded by given asio::strand instance

本文关键字:asio strand 保护 实例 运行时 检查 是否 代码      更新时间:2023-10-16

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

下面是一个伪示例:

...
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());

请参阅文档页面