Who here has experience with concurrency and multithreaded apps ?
Discussion
*tentatively raises hand* have experience but not much experience. I use it in hobby projects that have not gotten far.
What is "apps" in this case? My 3 months combined experience is limited to rust applications for Linux.
Apps where you connect to a udp socket. There are connection and disconnection methods that wrap the core connection code. These methods are executed async. It’s concurrent executions and many connect and disconnect calls can be made.
I fall in a special condition where the connect and disconnect method fall out of order. Like a disconnect gets called when a connect is still on going and vice versa. And I don’t want to just increase the timeouts, that hides the problem instead of solving it.
Are these out of order connect/disconnect requests from the same client?
I guess I am confused as to how they could overlap. Are you waiting on a handshake? Is this Aedile?
It’s not Aedile. If it was, I would’ve said so already. It’s a library at work for which I am now one of 2 maintainers.
They could overlap because they are executed concurrently.
Yes, it is from the same client.
I have to admit I am confused, but if you get a disconnect request from a client for which there is no established connection you can increment a disconnect counter in a mutex then whenever you complete a connect check for a positive disconnect counter, disconnect, and decrement.
If there is an established connection as indicated by a connection counter in the mutex then disconnect right away. It's kind of like counting parentheses.
Are there other sorts of requests that are arriving out of order that require an open connection to be processed? Does the close connection request give any indication of how many to expect?
No it’s all several connections (and disconnections) from the same client. But what you said have given me an idea. I’ll try using semaphores to protect the sensitive parts of the connection and disconnection code.
This worked by the way. I used it to lock access to the bare metal connection and disconnection code so it doesn’t overlap.
I am assuming this is on the server side not the app side? So you want to read the udp socket on one thread and then pass the packet to worker threads based on connection status?