-
Notifications
You must be signed in to change notification settings - Fork 61
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
Safely stopping waitForSubscriptionEvent()
from another thread.
#59
Comments
You are welcome, I am happy it is used 😄
Then maybe it would be a good idea to make
After calling
Yes, I can see that it would be useful to be able to close the WebSocket connection from the client side. Thanks for your remarks! |
Thanks for your replies. I indeed went with adding a new function in #60
I was considering making a PR to do this for every function, and removing the |
I like your arguments, and then I guess it is also reasonable to do the same with Plus maybe adding two mutexes?
Might this be something you are willing to do? |
First of all, thanks for the library. Very useful :)
When using subscriptions, it is necessary to call
waitForSubscriptionEvent()
, likely in a loop. However, since this can block arbitrarily long, it generally has to be put in a separate thread from a different event loop likeros::spin()
.When it's time to quit the program, it becomes necessary to stop the background thread. However, from what I gathered, I don't think there is a thread safe way to do this.
Firstly, both
waitForSubscriptionEvent()
andendSubscription()
mutate a memberevaluation_conditions_
. So they can't safely be called from different threads at the same time. I didn't look further, but it could be thatwebSocketRecieveFrame()
called fromwaitForSubscriptionEvent()
does more thread unsafe things.Secondly,
endSubscription()
only seems to ask the robot controller to remove the subscription. It doesn't do anything to stopwaitForSubscriptionEvent()
. Should communication with the controller be broken at this point, it may take arbitrarily long forwaitForSubscriptionEvent()
to return. Also, I'm not sure if the robot controller closes the websocket connection at all when the subscriptions are deleted. The documentation doesn't say anything on the subject.Note that maybe
endSubscription()
shouldn't interrupt a runningwaitForSubscriptionEvent()
. But then another function to do so would be very useful to cleanly terminate an application. Doing it in a separate function allows to limit thread safety guarantees to the interrupt function only, which wouldn't necessarily have to do an HTTP request. So that might keep things easier.The text was updated successfully, but these errors were encountered: