-
Notifications
You must be signed in to change notification settings - Fork 7
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
unit tests for ROS Thread Obj #42
Conversation
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.
Good work. I think we can merge this as it is.
I'll do some minor (cosmetic) changes, but I like what I see 👍 |
Actually, after reviewing the code I am thinking that it can drastically simplified by implementing everything inside the
Other things (that now will not be important since you'll change them):
|
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.
See my comment for the changes I would like you to implement.
Okie, just making the changes. As for the concerns you brought up, the first and third are related. I was trying to pass the |
Ah okay, that is correct then..but as you said, it will be fixed by my suggestions :) |
Yup 😊 But I'm running into a little bit of trouble. I've moved the functions into the class. However, class member functions have a type edit: one way could be like in |
I would do like in robot interface class. It seems the better option any way |
Codacy is complaining because of the C-style syntax needed to implement the wrapper approach. I am not entirely sure why one of the unit tests is failing on Travis, I'll look into it edit: I believe this is because the shared_ptr is partially thread-safe. Its control block portion is thread-safe, but the resource it manages (the int var) is not thread-safe. |
For the unit test, it's because it is probably not thread safe:
For the For codacy, it is right, but we don't care 😎 |
I've been puzzling through this get/set + lockguard approach for a while. If we keep the lock guard within just the get/set methods, it causes some problems.
For e.g: if 2 threads run that loop to increment var, then we might have a situation where: I think the lockguards may be needed within the thread functions themselves. For e.g this works:
What do you think? |
I think that your solution is okay. A better solution would be to get rid of the |
Ok added the safe methods 😄 |
@sarimabbas See my commits and try to understand what I did in order to make this class with a similar code style as the rest of the repo. I did some other medium severity changes, which should be pretty straightforward to understand (please report to me if you don't). The only thing that it's worth mentioning here is that in |
Ok merging! Good job @sarimabbas Now we can move to |
I understand, and thank you for the edits. I'll get started on the std::threads |
made a new branch because the other one started to get messy
for now, i used a mutex to lock and unlock the thread functions as needed to address the concurrency issue. hopefully when switching to shared-ptr with std::threads it may not be required.