A database server request thread is inherited from TThread. Each one creates a socket component that it uses to communicate with the database.
This has worked well in various other threaded applications I've written, it's just now I'm running into problems. This may be because the general activity of this application is much greater (although socket activity per thread is much less), though I'm not sure.
I would have thought if this was some kind of synchronisation issue, it wouldn't have worked at all.
What I have found is that after X (random amount but usually more than 10), the socket state changes from wsConnected to wsConnecting. It appears that because the database requests are serviced so quickly Winsock is somehow becoming flooded(?) and the WSAGetLastError returns WSAEWOULDBLOCK. This is then manifesting itself at the time of SenddStr (since the state is obviously not wsConnected).
At the time of SendStr, if the state is wsConnecting I've tried waiting around a bit (calling the ProcessMessages of the Socket object) to only proceed if it becomes connected.
The above results in the application flying through the first few batches of requests and then freezing for ages and then proceeding very slowly.
Really not sure I've fixed it. Is there a better solution to the one that I've come up with?
Thanks
Steve
Main Topics
Browse All Topics





by: ciulyPosted on 2008-03-03 at 07:07:11ID: 21032124
I'm curious how you are threading the ICS components. because them beeing non-blocking and relying on events, the events are fired in the calling threads context so you might need to synchronize access to some resources.
and since the error is random, it could be just because of that: badly or not sycnhronized access to a commonly used resource.