I've hit a funky TSan warning: "data race on vptr (ctor/dtor vs virtual call) in StartImpl()". I fail to see a race as the object is constructed in the main thread and then a worker thread is started:
struct Client : public ClientInterface {
Client() {
auto op = new Op{this};
thread_ = std::thread([op] { op->StartImpl(); });
}
...
};
void Op::StartImpl() {
std::cout << "This is a race: " << owner_->VirtualFunction() << "\n";
}
struct TestClient : public Client {};
int main(int argc, char **argv) {
TestClient().Wait();
return 0;
}
The full report with a minimal/complete repro is here: https://github.com/google/sanitizers/issues/1063
What am I missing? Does TSan miss the fact that all data stores happen before the worker thread is started? Or is this about the vtable pointer which is adjusted during the object's construction in the main thread?
Thanks!
Oleg.