Closed joaquintides closed 1 year ago
I don't think you should duplicate all the BOOST_ASSERT functionality. That's what it's for.
For the attribute, see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h, the Mutex
class.
I don't think you should duplicate all the BOOST_ASSERT functionality. That's what it's for.
Do we at least keep BOOST_UNORDERED_DISABLE_REENTRANCY_CHECK
, or not even that?
An automated preview of the documentation is available at https://200.unordered.prtest2.cppalliance.org/libs/unordered/doc/html/unordered.html
Yes, we should have a way to disable the reentrancy check independently, for performance reasons.
An automated preview of the documentation is available at https://200.unordered.prtest2.cppalliance.org/libs/unordered/doc/html/unordered.html
Merging #200 (1979ce9) into develop (bd24dfd) will increase coverage by
0.00%
. The diff coverage is100.00%
.
An automated preview of the documentation is available at https://200.unordered.prtest2.cppalliance.org/libs/unordered/doc/html/unordered.html
An automated preview of the documentation is available at https://200.unordered.prtest2.cppalliance.org/libs/unordered/doc/html/unordered.html
This looks good to me as well.
I feel like we should document the BOOST_UNORDERED_DISABLE_REENTRANCY_CHECK
macro, no? It seems like it's automatically disabled in release builds when NDEBUG
is defined but I think it'd be good if users know about this configuration macro in particular.
If we also wish to keep the same style of test, there's the UNORDERED_AUTO_TEST
macro which can be used but I don't really think this is a big deal at the end of the day.
Regarding support of Clang thread safety analysis:
I've written a draft of what it'd take to support it here. I've found severe limitations:
Reentrancy detection The anaysis is strictly intra-procedural. So, reentrancy is not detected here:
using mutex=boost::unordered::detail::foa::annotated_mutex<boost::unordered::detail::foa::rw_spinlock>;
using lock_guard=boost::unordered::detail::foa::reentrancy_checked<boost::unordered::detail::foa::lock_guard<mutex>>;
static mutex m;
void foo()
{
lock_guard lck{nullptr,m};
}
void bar()
{
lock_guard lck{nullptr,m};
foo();
}
int main()
{
bar();
}
and the following explicit annotation is needed:
void foo() BOOST_UNORDERED_EXCLUDES(m)
{
lock_guard lck{nullptr,m};
}
void bar()
{
lock_guard lck{nullptr,m};
foo(); // warning : cannot call function 'foo' while mutex 'm' is held [-Wthread-safety-analysis]
}
which is a PITA as we'd need to annotate all the internal and external functions of foa::concurrent_table
. Even so, the following reentrancy is again not detected:
void foo() BOOST_UNORDERED_EXCLUDES(m)
{
lock_guard lck{nullptr,m};
}
template<typename F>
void bar(F f)
{
lock_guard lck{nullptr,m};
f();
}
int main()
{
bar([]{foo();});
}
because the lambda function is not annotated --and can't be, being user code. So, this Clang's analysis is useless for detecting reentrancies in user code.
Race detection
To detect unprotected access to data, the analysys tool requires annotations like this:
static mutex m;
static int balance BOOST_UNORDERED_GUARDED_BY(m);
We can't have this annotation in our data structure:
foa::table_core
, which can't access the mutex in the derived class (except with incredible contortions).group
array is guarded by the n-th mutex in the group_access
array: annotations can only use compile time expressions (typically, simple references to data members).For all these reasons, I think we should abandon this line.
For all these reasons, I think we should abandon this line.
No objections from me.
I feel like we should document the BOOST_UNORDERED_DISABLE_REENTRANCY_CHECK macro, no? It seems like it's automatically disabled in release builds when NDEBUG is defined but I think it'd be good if users know about this configuration macro in particular.
I'd rather leave this undocumented (and so little publicized), just as we did with BOOST_UNORDERED_DISABLE_SSE2
etc. I don't think there'll be many situations where the user may legitimately need to disable it (entry_trace
lists will typically be <=2 in size), and there are situations where it can be unlegitimately disabled to let code pass that we have officially banned.
I agree that BOOST_UNORDERED_DISABLE_REENTRANCY_CHECK
should be documented. It's not an implementation detail or a testing artifact; its purpose is to be user-settable, and it has a specific and legitimate use - to disable reentrancy checking in debug builds for performance reasons.
My suggestion is to either add a "Configuration Macros" subsection to the reference (after the "Guarantees") and put it there, or add a dedicated "Reentrancy Detection" section.
An automated preview of the documentation is available at https://200.unordered.prtest2.cppalliance.org/libs/unordered/doc/html/unordered.html
An automated preview of the documentation is available at https://200.unordered.prtest2.cppalliance.org/libs/unordered/doc/html/unordered.html
PR open for discussion:
BOOST_UNORDERED_(DISABLE|ENABLE)_SSE2
).__attribute__((capability("mutex")))
and am not sure how the thing is supposed to be used and whether we have to conditionally add it or not.