I am writing a complicated program with a server and multiple clients. The server crashes on a line that looks like this:
printf("Done parsing input\n");
The call stack shows the error in _flsbuf where in assembly I found the ecx register to be NULL so I can see why it would crash, but how on earth did this happen, it seems to be a simple printf statement.
Another interesting thing about this, is that the clients communicate with the server and send data that needs to be parsed. This is in an infinite loop, and it goes through successfully 20-30 times before it crashes.
Any ideas?
Curtis
That can definitly cause problems like this. (however you may still have other problems too, but you have to fix this!)
In a C/C++ program (in VC or BC or BCB) you have to start a new thread using the _beginthread() or _beginthreadex() functions. These functions will call CreateThread() to have windows create thread for you, but they do other important things. In particular they initialize the RTL--Run time library--for the new thread. The RTL contains a lot of static data that must be initialized on a thread-by-thread basis.
Make that change and see if it improves things. (even if it doesn't fix everything, keep the change!)