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 :) )
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.
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).
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.
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.
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
@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'.)