Thread: Multi-Threading

  1. #1
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227

    Multi-Threading

    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. . .

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I got it to work, but the program is messed up.
    You're going to have to be a lot more specific than that. Post some source code.

    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.

  3. #3
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    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. . .

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    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?

  5. #5
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    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. . .

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. overlapped I/O and multi threading
    By krishnampkkm in forum C++ Programming
    Replies: 2
    Last Post: 06-22-2009, 03:27 PM
  2. Multi Threading
    By beon in forum C Programming
    Replies: 5
    Last Post: 12-04-2006, 09:21 PM
  3. Replies: 6
    Last Post: 06-02-2006, 08:32 AM
  4. starting to learn multi threading
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2004, 01:44 PM
  5. Multi Threading
    By IceBall in forum C Programming
    Replies: 7
    Last Post: 07-13-2003, 03:01 PM