Thread: 2 loops at once?

  1. #16
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981

  2. #17
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    Cool, but now another problem. I now get a million of linker errors such as:

    [Warning] cannot find entry symbol _mainCRTStartup; defaulting to 00401000
    [Linker error] undefined reference to `GetStdHandle@4'
    [Linker error] undefined reference to `FillConsoleOutputAttribute@20'



    I thought i heard about this before somewhere, but i cant remember where.
    Keyboard Not Found! Press any key to continue. . .

  3. #18
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    Hahahahaha
    I was screwing around with some options and accidently got it to work...I think
    Keyboard Not Found! Press any key to continue. . .

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

    ....?

    Okay guys, you are probably getting bored with me by now, but I am getting the craziest errors ever. When the program that I wrote runs all sorts of wierd things happen. The text that is supposed to be displayed gets displayed at different parts and times and all these wierd hexadecimal things come up in the place of the missing text. Also, the program just randomly closes.
    Is this common? If you need the code just ask, cuz this project I am making is just helping me learn new things and its kind of big and sloppy.
    Keyboard Not Found! Press any key to continue. . .

  5. #20
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    It's entirely possible that your data is getting corrupted by the thread. If the thread is accessing the same data that the main program is (including cout and printf), you'll get problems with things getting mixed up since threads don't share nicely (unless you do synchronization stuff).
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #21
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    oh god....
    I guess I learn new things.....
    Is there a way to tell if that is happening?
    Keyboard Not Found! Press any key to continue. . .

  7. #22
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Not really

    Why do you need two loops running simultaneously anyway? If at all possible, I suggest you do it in just one loop. It's usually not worth the headache of thread-related problems (although there ARE uses for threads).
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #23
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Yeah, for example, you could make a for loop and execute one function on even numbered loops and the other function on odd numbers.
    What is C++?

  9. #24
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Yeah, for example, you could make a for loop and execute one function on even numbered loops and the other function on odd numbers.
    Well, that would be ONE way of 'faking' multithreading (ironical isn't it, he wanted multithreading because he wanted to use two loops side by side)

    But if there's no problem with the loops running side by side, there should be no problem even if the two function calls are within the same loop:
    Code:
    while(!done)
    {
       doLoopStatements1();
       doLoopStatements2();
    }
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  10. #25
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    Well, I dont need to, but I'd like to.
    And I understand what you are saying about combining the loops.
    Now that I think about it actually, my program used to run like that, but it didnt do everything I wanted it to because one of the loops keeps updating itself, while the other is the interactive part of the program. The second one doesnt continuously run. It stops for input and things like that. So it would it would kind of ruin the whole point of the first loop. I will google synchronization and see what it comes up with.
    Keyboard Not Found! Press any key to continue. . .

  11. #26
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    But if there's no problem with the loops running side by side, there should be no problem even if the two function calls are within the same loop
    ????What do you mean by that?????
    Keyboard Not Found! Press any key to continue. . .

  12. #27
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>It stops for input and things like that.
    You would do well to look into a function such as _kbhit() (or whatever your compiler might have), even though it's nonstandard. What it does is return non-zero if a key has been pressed but has not yet been read by cin.get() or whatever, and false if no key has been pressed yet. That way in your loop you can check kbhit() and if it returns true, THEN get user input... and if it returns false, then screw input and keep on going with whatever else you're doing.

    **EDIT**
    >>????What do you mean by that?????
    Basically I'm restating that you should mash your two loops together Although the blocking input (cin) makes that a little more complicated, the solution I just posted about kbhit() should help.
    Last edited by Hunter2; 09-08-2004 at 09:44 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  13. #28
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    I'll try that out!
    Hey I actually understand what you are saying this time!
    Oh crap porbably should get some sleep for school tomorrow...God I hate ninth grade....

    **EDIT**
    Wait a minute. If I use the kbhit() thing wouldn't that require an extra keystroke?
    Last edited by DeepFyre; 09-09-2004 at 02:47 PM.
    Keyboard Not Found! Press any key to continue. . .

  14. #29
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> If you need the code just ask, cuz this project I am making is just helping me learn new things and its kind of big and sloppy.
    If you want to get your learn-on, then post it

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loops Trouble
    By rlframpton in forum C Programming
    Replies: 2
    Last Post: 04-17-2009, 01:08 AM
  2. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 01:18 AM
  3. recoursion or loops?
    By Mecnels in forum C++ Programming
    Replies: 2
    Last Post: 01-14-2002, 12:09 PM
  4. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 04:28 PM
  5. for loops - newbie q's
    By Narciss in forum C Programming
    Replies: 8
    Last Post: 09-26-2001, 02:44 AM