Click to See Complete Forum and Search --> : Threads keep crashing... Probably some stupid newbie prob..


BlackSun
December 14th, 2004, 01:26 PM
Ok so I'm doing an app in VC++ 6. It's an MNC app, and I'm trying to make it multithreaded, and now I have of course run into a problem I can't solve...
I've read articles on msdn, but I seem to be too stupid to get them.
So heres my problem :

I have my dialog here, and in it I have a function that I'm trying to get to work.

It looks something like this ;


UINT MyClass::Server (LPVOID pParam)
{
CSocket sock;
// some more declarations and stuff done, so far all is good
if (!sock.Create(the_port))
MessageBox("Couldn't create..."); // Crashes before I'm here ...

}


So, why does it crash when I'm using CSocket in the thread ? Tried using SOCKET too, and then it doesn't crash, but then I can't do anything with it ....

TIA
BlackSun

kirants
December 14th, 2004, 03:05 PM
what is the_port.. That code doesn't help much. Did you try stepping in to Create and see at what point it is crashing ?

BlackSun
December 14th, 2004, 03:32 PM
ahh ! the_port is just an integer with a number, the port to be used.

It crashes where the comment says it does, at the Create() function. All my code work if I just put it in a regular function in the dialogclass, but as soon it's moved to the threadfunction it crashes ...

Mathew Joy
December 16th, 2004, 12:34 AM
It may be better if you could post the stack you got at the time of the crash. As common in multithreaded programs, the crash may seem to occur from a simple statement, but the actual reason might be somewhere else.

BlackSun
December 16th, 2004, 07:05 PM
Pardon my stupidity, but exactly how do I post the stack ? And what is it ?

Andreas Masur
December 17th, 2004, 03:49 AM
Pardon my stupidity, but exactly how do I post the stack ? And what is it ?
Run your application in the debugger...if the crash occur, press the 'Retry' button and you will be brought back to the debugger.

It will point to the line which caused the assertion. Open the call stack combobox (or open it individually with ALT + 7) and scroll down until you find the first function that you have written. Click on the line and the corresponding line/file will be displayed in the editor. Then check the variables involved to see whether everything is initialized and set correctly etc.