RTC Toolkit
1.0.0
|
The pre-defined contracts defined below have associated Doxygen macros that are meant to be used on:
When used on a class it determines the default contract on the whole class. This can then be further refined on a member function level. For example in the class Foo
the member Foo::Bar
is thread-compatible, but Foo::Baz
is refining the contract to be thread-safe:
Classes that inherit a contract from a base-class must abide by that contract. E.g. Foo
below must remain thread safe as base class Base
specified that contract:
Thread-safe - means that member or non-member functions are safe to call in parallel.
Thread-compatible - applies to classes as a whole and means that no external synchronization is required for parallel accesses to separate class instances or for const-only accesses on the same instance. Mixed const/non-const access must be externally synchronized.
Thread-hostile - means that parallel access is never safe. This may occur if e.g. a free function (or const member function) accesses a global shared state in a non-const fashion.
This table summarize operations that are safe in parallel for the different classifications:
Parallel operation | Thread-safe | Thread-compatible | Thread-hostile |
---|---|---|---|
Const-only | x | x | |
Non-const w/ separate instances | x | x | |
Non-const w/ same instance | x |
See also related terminology:
If not documented otherwise the following classification apply:
The following Doxygen macros are defined and adds a "Thread Safety" paragraph with optional commentary.
@thread_safe
and @thread_safe{comment}
.@thread_compatible
and @thread_compatible{comment}
.@thread_hostile
and @thread_hostile{comment}
.The macros are used in class or function declarations:
If macro is used on the class-level it defines the behaviour for the whole class. Exceptions for individual member functions is allowed, e.g.:
The adopted terminology comes from B. Stroustrup (2000), "The C++ Programming Language" Appendix E, also summarized on cppreference.com.
The terms are summarized even further here:
noexcept
keyword.Additionally there's the neutral exception guarantee that will in template contexts adopt the guarantee of the provided template parameter.
If not documented otherwise the following classification apply:
The following Doxygen macros are defined and adds a "Exception Safety" paragraph with optional commentary.
@exception_strong
and @exception_strong{comment}
for strong exception guarantee.@exception_basic
and @exception_basic{comment}
for basic exception guarantee.@exception_neutral{comment}
for neutral exception guarantee (comment with additional detail should be provided so there is no macro version without argument).@exception_no_guarantee
and @exception_no_guarantee{comment}
for the no exception guarantee.And additionally for a custom entry:
@exception_safety{name
, comment} for non-standard exception guarantees. Comment should specify the details.There is no macro for the nothrow exception guarantee as C++ has a noexcept
specifier. If noexcept
is conditional the documentation should clarify using the existing macros.