also... debug can be very usefull for certain things
for example... lets say you were doing a console app and for debugging you were using cout statements. If you:
#ifdef _DEBUG
cerr>>"I got an error with a null pointer";
#endif
this could be useful information to you. Then when you switch over to "release" you will not have these pre-processor directives.
As for multi-threaded... the general explanation can be though of like this:
3 cars are driving down the road going to the same destination A. They have all been traveling on the same road and they come to a 3 way interseciton. They can either take roads x, y or z to get to A. Car one goes by x, two by y and three by z. Then they meet at A. The cars are the program which then creates the threads (x,y,z) which all run together and then meet up at the end (not necessarilly at the same time). Basically the all drive to the same place concurrently. When the program runs a thread it will run concurrently with the rest of the program and join back to the program at a later time.
If you're new to C++ and/or C, you might want to wait a bit before diving into multithreaded programming. It's a little complex.
The biggest thing that can bite you is variable access. Say you have two threads, A and B, and a long variable named counter, with an initial value of 4. "A" needs to execute this code:
[tt]counter*=3[/tt]
And "B" needs to execute this code:
[tt]counter+=2[/tt]
The question is: What's the value of counter?
And the answer is: It depends on the order in which the statements were executed.
If thread A executes first, you get 14. If thread B executes first, you get 18. If they execute at the same time (which is possible on a dual-cpu machine), the results are undefined.
So, what you need to make sure is that you try not to access any global variables from within a thread. It's best to lump anything the thread needs into a struct and pass it to the thread routine.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.