Menu

#20 Ability to check that we're on a specific strand

open
nobody
None
5
2012-12-12
2012-12-12
Anonymous
No

It would be great to be able to code assertions into our methods that the code is being called as expected. This can also serve as useful documentation fo developers. For example:

class Foo {
public:
Foo(asio::strand& strand)
: strand_(strand) {
}

void foo() {
assert(strand_.running());
...
}

private:
asio::strand& strand_;
};

strand::running() would return true if the strand is running in the current thread. The assertion states that foo must be called from strand_.

This information is already maintained by the strand implementation. strand::dispatch() needs to know if the currently thread is executing the strand already so that it can decide whether to execute the handler immediately (on the current thread) or post it to a queue of handlers.

Discussion


Log in to post a comment.