thwang
thwang

Reputation: 65

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

I would like to add a runtime assertion to my code that checks if the code is guarded by a given strand.

Here is a pseudo example:

...

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

Upvotes: 3

Views: 191

Answers (1)

sehe
sehe

Reputation: 393507

I think you might be looking for

 assert(my_strand.running_in_this_thread());

See the documentation page

Upvotes: 3

Related Questions