依赖 brpc 作为第三方库时使用 Tsan 报错
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start by reproducing the warning with the two shown tests, built with ThreadSanitizer, while depending on brpc. Then inspect brpc's mutex.cpp and the interaction between its pthread_mutex_lock override and bthread's internal implementation. Done means the reproduction no longer produces the reported Tsan warning without breaking the pthread and bthread mutex tests.
Written by the indexing model from the issue text.
Description
- 项目中依赖brpc作为第三方库时出现的报错问题: brpc中的mutex.cpp覆盖了pthread_mutex_lock的实现,疑似导致tsan识别不了bthread内部实现的pthread_mutex_lock,导致出现了告警,请问有办法解决这个warning吗?一个简单的复现方式
#include <bthread/bthread.h>
#include <gflags/gflags.h>
#include <gtest/gtest.h>
namespace my::test {
class TsanCheckTest : public ::testing::Test {};
int counter;
std::mutex mutex_std;
pthread_mutex_t mu;
const int kIncrementsPerThread = 100;
void* Locker(void*) {
for (int i = 0; i < kIncrementsPerThread; ++i) {
pthread_mutex_lock(&mu);
counter++;
pthread_mutex_unlock(&mu);
}
return nullptr;
}
TEST_F(TsanCheckTest, MutexUsedInPthread) {
pthread_mutex_init(&mu, nullptr);
const int num_threads = 8;
pthread_t th[num_threads];
counter = 0;
for (int i = 0; i < num_threads; ++i) {
ASSERT_EQ(0, pthread_create(&th[i], nullptr, Locker, nullptr));
}
for (int i = 0; i < num_threads; ++i) {
ASSERT_EQ(0, pthread_join(th[i], nullptr));
}
ASSERT_EQ(counter, num_threads * kIncrementsPerThread);
}
TEST_F(TsanCheckTest, MutexUsedInBthread) {
const int num_threads = 8;
bthread_t th[num_threads];
counter = 0;
for (int i = 0; i < num_threads; ++i) {
ASSERT_EQ(0, bthread_start_urgent(&th[i], nullptr, Locker, nullptr));
}
for (int i = 0; i < num_threads; ++i) {
ASSERT_EQ(0, bthread_join(th[i], nullptr));
}
ASSERT_EQ(counter, num_threads * kIncrementsPerThread);
}
} // namespace my::test
- Dominant language
- C++
- Stars
- 17.6k
- Forks
- 4.2k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 72
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/brpc
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 2 days
-
endpoint2hostname() prints a byte-swapped port for IPv6 endpointsPossibly taken @0z5a claimed this 8 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 2 days
-
perf(butil): ARM64 (aarch64) performance and modernisation improvements across atomics, CRC32C, spin-wait hints, and fast timersPossibly taken @jimmystewpot claimed this 2 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 12/100
Maintainers usually reply within 2 days
-
file:// naming service takes a comment after the address as the tagPossibly taken @0z5a claimed this 8 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
Maintainers usually reply within 2 days
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Maintainers usually reply within 2 days
Similar issues
-
agent:Windows bug in progress pri:medium sev:low testing windows
Difficulty 1/5 Under an hour Newbie friendliness 91/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
protocolbuffers/protobuf#31768 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
godotengine/godot#125651 ·
Maintainers usually reply within 1 day
-
Android: with view recycling on, a recycled View keeps its nextFocusLeftPossibly taken A pull request linked to this issue is open or already merged. OpenNeeds: Triage :mag: Platform: Android
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
react/react-native#60167 ·
Maintainers usually reply within 2 days
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 63/100