## Recommended Posts

basvanmeurs    122
Hi, I've been working on a win32 application that starts 2 threads, which both connect to the same FTP-server and do various downloads/uploads/renames/deletes etc. at the same time. The main function kind of works like this:
	//Initialise winsocket
FTP::init();

while(true);

The problem is that after a short while (about a minute) the application crashes. But if I make two seperate applications, each one just having one of the two threads, it will run for hours without a problem. Personally, I don't see any reason why this should happen, as the threads do not share any variables (maybe only in winsock, but this is the concern of winsock, right?) Does anyone have any idea what might be the problem here? Cheers, Bas

##### Share on other sites
Evil Steve    2017
There's nothing wrong with using winsock in threads, in fact it's the usual way to do things.

What do you mean the application crashes? What does the debugger tell you is wrong? You are running it in the debugger rather than just running blind, aren't you?

##### Share on other sites
basvanmeurs    122
It seems to crash on random points and with random codes.

I've seen C000001D, C0000096 and C0000005.

And btw, I don't know a good win32 debugger.. Actually, I haven't got much experience in win32 at all.

##### Share on other sites
Evil Steve    2017
Visual Studio Express 2008 is free and comes with an excellent debugger. It's practically impossible to write any code without a debugger. Well, I suppose it's possible, but it's an extremely bad idea and will take an extremely long time to track even the simplest bugs down.

##### Share on other sites
basvanmeurs    122

As a matter of fact, I've spent some time today searching for a decent debugger.

##### Share on other sites
polymorphed    272
This might be a stupid question, but are you making sure your threads are not trying to write to the same memory locations at once? Since it crashes randomly, this could be the cause.

##### Share on other sites
basvanmeurs    122
Actually, they don't share any variable.. so I'm pretty sure that it's something in winsock.

##### Share on other sites
basvanmeurs    122
Ok I've found out where the problem occurs.

Most of the time, it occurs at the instant of 'throwing' a user-defined Exception. The Exception is created correctly, but when it is thrown the control never reaches the catch-statement, and instead the thread crashes (dialog pops up).

Is there any way it coule be related to the thread heap size? And how can I check for overflow?

##### Share on other sites
basvanmeurs    122
This is utter crap. I don't know what is wrong but it has something to do with the memory.

##### Share on other sites
ApochPiQ    23003
Please post details of your crash situation. What is the exact error message when the app dies? What is the current state of the program stack when it dies? Why is the exception being thrown and what does the code around that context look like? How is the exception class implemented? How do you know you don't have any shared memory issues?

You might try downloading and running Intel's Thread Checker to see if it detects any problems. It's an excellent tool, but be warned, it can take a long time to run.

##### Share on other sites
DerekSaw    243
Make sure each of your 'thread' functions are wrapped with try/catch. Exception can't get out from its own thread and being catched in other threads.