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

时间:2014-04-14 08:07:18

标签: c++ boost-asio

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

这是一个伪示例:

...

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

1 个答案:

答案 0 :(得分:1)

我想你可能在寻找

 assert(my_strand.running_in_this_thread());

请参阅the documentation page