-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix data race in NormalEstimationOMP
on Windows
#2770
Fix data race in NormalEstimationOMP
on Windows
#2770
Conversation
You are right that we should use free function, not member. However, to the best of my knowledge, this is the case already. In order to call the member function you would need to prefix with |
Because |
No, in our case we have a templated base class and your statement is not correct. I urge you to a) add a print statement and check which function gets called; b) read up on the topic, e.g. this stack overflow thread. Edit: that said, I think we can merge your change since it makes the intention of the code more clear. I just wouldn't call it a "fix", rather a "style improvement". |
Sorry, I wasn't aware of the case of template base class member. And sorry for my lack of explanation about my environment. As the description that you referred, a behavior of MSVC is non-comforming. It compiles |
I noticed that disclaimer about MSVC, but since the answer was given 8 years ago I assumed Microsoft had enough time to fix this. Which version do you have? And you confirmed with a print statement that the wrong function is used? |
Microsoft corrected this behavior at version 15.5 (released in Dec 2017). Surely, the following code compiled by MSVC 15.9 with default compiler option prints "free". But MSVC 2015 (Update 3) will print "member" void foo() { std::cerr << "free" << std::endl; }
template <typename T>
class A
{
public:
void foo() { std::cerr << "member" << std::endl; }
};
template <typename T>
class B : public A<T>
{
public:
void bar() { foo(); }
};
int main()
{
B<pcl::Normal> b;
b.bar();
} |
OK, thanks for the research, we both learned something today 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying things.
NormalEstimationOMP
NormalEstimationOMP
NormalEstimationOMP
on Windows
Problem
The function
computeFeature
of the classpcl::NormalEstimationOMP
calls the member functioncomputePointNormal
. And thiscomputePointNormal
accesses the member variablexyz_centroid_
andcovariance_matrix_
.These variables are written at the same time in using OpenMP, so they will be destroyed.
Solution
Replace with the non-member version.