Thread: 2 actions at once

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    30

    2 actions at once

    how do i perform 2 actions at same time in c++? c++ only seems to run codes one by one sequentially.

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    You need to look into multithreading. What OS/compiler are you using?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    multi-threading or multi-process solutions. Its OS and sometimes compiler specific so we'll need more info before helping you.

    Dang foiled again by XSquared.

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Geez. Thantos. Work on your typing speed.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    The fingers are doing their thing just fine. Its the brain telling them what to type is the slow one today.

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    30
    o/s = operating system im using? im using windows xp and dev c++, the beta one

  7. #7
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Thantos: Just today?
    Chobo: Here is an example of threading.
    Last edited by XSquared; 04-25-2004 at 07:03 PM.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    30
    does this require knowledge of window programming?

  9. #9
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Nope.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  10. #10
    Registered User
    Join Date
    Mar 2004
    Posts
    30
    oooooooo this is interesting stuff but a bit advanced for me >.< damn programming hard...

  11. #11
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Why do you think that your program needs multithreading?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  12. #12
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    @XSquared: Mainly today
    @Chobo: Like all things learning the basics of programming is the hardest part. Multithreading and multiprocess solutions are not a giant step in difficultly once you have those skills. Be patient and you'll get it

  13. #13
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    If you are a novice in C++, I doubt the program you're making would benifit from threading. There are cases where threads can lower the performance of the program, and you can create serious issues if you do not have experiance with them. Just learn as much as you can first, then decide to use them later.
    Do not make direct eye contact with me.

  14. #14
    Registered User
    Join Date
    Mar 2004
    Posts
    30
    ok -.- i just wanted to add special feature to my program
    Code:
    #include <windows.h> 
    #include <iostream>
    #include <conio.h>
    
    using namespace std;
    
    void gotoxy(int x, int y)
    {
      COORD coord;
      coord.X = x;
      coord.Y = y;
      SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    }
    
    int main()
    {
        int count;
        int i, ii;
        gotoxy(3,0);
        cout << ":";
        for (ii = 20; ii >= 0; ii--) {
            if (ii >= 10) {
                gotoxy(1,0);
                cout << ii;
            }
            else {
                gotoxy(1,0);
                cout << " ";
                gotoxy(2,0);
                cout << ii;
            }
            for (i = 60; i >= 0; i--) {
               if (i >= 10) {    
                   gotoxy(4,0);
                   cout << i;
                  Sleep(50);
              }
              else {
                  gotoxy(4,0);
                 cout << "0";
                 gotoxy(5,0);
                  cout << i;
                  Sleep(50);
               }
            }
        }
        getch();
        return 0;
    }
    this program just basically counts down from 20:00 to 0:00. but wat if i want the program to accept an input from the user without interupting the count down? if i use cin, it would stop the count down until the input has been received.

  15. #15
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    lookup kbhit(), it will tell you when the user hits a key and using getche() you can read it in one by one.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Automating program B based on program A's actions
    By AELCoder in forum C Programming
    Replies: 3
    Last Post: 06-13-2008, 11:14 AM
  2. Unit Actions
    By DavidP in forum Game Programming
    Replies: 20
    Last Post: 05-28-2004, 09:18 PM
  3. Actions of CreateDirectory
    By golfinguy4 in forum Windows Programming
    Replies: 3
    Last Post: 06-30-2002, 10:41 AM
  4. Need Help with Bitwise actions!
    By gg in forum C Programming
    Replies: 4
    Last Post: 02-07-2002, 10:57 AM