Hey, hey, hey guys I'm back again with multi-threading!
This time though, I got it to work, but the program is messed up.
Someone said this could be because the thread was getting corrupted. How could I do it so that it doesnt get corrupted?
Hey, hey, hey guys I'm back again with multi-threading!
This time though, I got it to work, but the program is messed up.
Someone said this could be because the thread was getting corrupted. How could I do it so that it doesnt get corrupted?
Keyboard Not Found! Press any key to continue. . .
You're going to have to be a lot more specific than that. Post some source code.I got it to work, but the program is messed up.
Multi-threading is a hard thing to get used to, because often we are used to programming in a sequential order, and this is one of the complexities of OOP.
I should have probably rephrased that. I kind of meant what would cause a thread to be corrupted, or are there like a million answers?
Keyboard Not Found! Press any key to continue. . .
Check for areas where different threads are writing to the same location in memory. For instance, is there a global variable that both threads are changing?
dang, you guys are good.
well there was, and i will edit it so that they dont use the same variable.
thanks in the meantime!
Keyboard Not Found! Press any key to continue. . .
>>I kind of meant what would cause a thread to be corrupted
Generally speaking it's not threads that become corrupted (sorry if I gave you that impression before!). It's a problem of sharing - if more than one thread accesses the same variable, the data might get corrupted. That's what I meant
>>i will edit it so that they dont use the same variable.
That's one solution. Another is to use thread synchronization objects like critical sections, mutexes, events etc. to be sure that only one thread accesses the object at a time. If you're doing this with Windows API, look into CRITICAL_SECTION, InitializeCriticalSection and EnterCriticalSection (there are related functions for leaving/destroying the critical section, there should be links from the first 2 on MSDN though).
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.