Multithreaded OO Sockets deadlocks

I wonder if it is possible to write a multithreaded object oriented socket library without getting deadlocks.

The only solution I have is a thread per connection design.

I test it by having a client connect to a server and sends a piece of data and the server replies and then the client disconnects. The server also have it's listening socket opening and closing. The timing between the two is varied. Eventually it deadlocks. Even ACE fails this test. (Funny thing is that ACE tried to fix it using flags like we did but there is still a hole there :) )
I've never gotten a deadlock in any of my networking designs....
maybe you should have worked for me back then ..... or maybe... you haven't torture tested your work...hmmm.

Is that you Mike? You left me with quite an interesting deadlock in that library, not to mention the log output to pick through.

I think ACE is the only common example I can comment on as source is available. I'll try to upload a perl script as a client for you to try. It's better if converted to C/C++.

Oh. that library and ACE took around 10000 to 15000 attempts before it deadlocked.
Last edited on
I'd rather not work for you. Or anyone for that matter. I've sent millions(Billions? Trillions? possible.) of packets across my networking code.

No. My name is Stephen.

This is a c++ forum.

Cool.

Hi Stephen, I bet you can't guess what my name is without going to my profile! ;D

edit: fixed typo
Last edited on
I wonder if it is possible to write a multithreaded object oriented socket library without getting deadlocks.
Is this a throw away comment? You've not actually provided any detail on anything you've done.

Is that you Mike? You left me with quite an interesting deadlock in that library, not to mention the log output to pick through.
Poor old Mike. I bet he gets blamed for everything.
Last edited on
mike designed a really beautiful socket library, it looked like ACE (adaptive communication environment), wink wink, but it deadlocks. Thinking ACE being community driven should have this solved but it had the exact same problem. Sockets are by nature something asking for deadlocks. Comms flow one way and also the other way which is how deadlocks happen. I can have some control when it is one acceptor, one connector and one thread but when the connections are greater than the number of threads then you have to go through a select and a dispatcher which is where the problem is. Wife willing I will try to repeat this with ACE just to demonstrate.

I know this is a C++ forum, the perl is an external generator to tickle the C++ server. My general principle is that you can use any tools that exists to test your C++ code (so that people would write test code).
Sockets are by nature something asking for deadlocks. Comms flow one way and also the other way
It's UDP/TCP that are bidirectional. The Socket's library is just a general comms library that provides a file interface.

it looked like ACE
Maybe it looked too much like ACE. Was the intent to use streams? Maybe you should have stuck with ACE and fixed the problems there.

but when the connections are greater than the number of threads then you have to go through a select and a dispatcher which is where the problem is.
I can sort of see race conditions and these become more pronounced as the network speed ramps up.

Do you really expect to have an unrelaible high speed async network? It looks like that's what you're testing.
closed account (S6k9GNh0)
Boost ASIO was made for things like this. They provide a way to efficiently make a thread pool and a way to efficiently use the thread pool for multiple connections asynchronously. Also, Boost ASIO can be header based or compiled. It can be optimized for wanted executable size, etc.
Last edited on
Boost ASIO was made for things like this. They provide a way to efficiently make a thread pool and a way to efficiently use the thread pool for multiple connections asynchronously.
But does it work? It would be interesting if khamara could run his test suite over such an implementation.
closed account (S6k9GNh0)
I'd give my IRC library example but I messed that up awhile back and it's rather horrid looking at the moment, not to mention I have an incredibly ugly file layout. I can remake the example in a day though... I just need to fix up my Linux partition and get back to work :P
Last edited on
ACE is doing more than that. It deals with Tasks, Queues and dispatching.

An app that sends the odd message across the World Wide Internet isn't quite the same thing as a high throughput app that ruins on a high speed LAN.

You have to compare like with like.
@337: I believe I saw you post that you were chris in another topic... I think?
closed account (3hM2Nwbp)
@kbw - I couldn't make boost::asio fail in an unexpected way with all of the hardware available to me. (I consider the machine running out of available sockets 'expected'.)

The strand concept is designed pretty well.
Last edited on
My username is xander337. as in Alexander, or Alex. Though my older brother's name is chris.
The strand concept is designed pretty well.
Pretty much all of these implementations are well designed. The question is do they work.
Last edited on
closed account (S6k9GNh0)
What do you mean "do they work"?
Topic archived. No new replies allowed.