Thread: Multiprocessing variation question

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    145

    Multiprocessing variation question

    I was just wondering, for doing two things at once, if the following was possible...

    Code:
    while (doing something)
    do something else
    I was thinking like running a function in the ( ) of the while loop, which would technically mean run that WHILE also running the things inside the loop. Any help?
    "Um...well..."
    -Kyoto Oshiro

  2. #2
    That's totally fine, but it's technically not being run at the same time - you would need to create Multi-process code for that ie. "Threading".
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    What happened to that thread example I gave you? j/k
    Stiff is mostly right, but consider this: a function like kbhit() is interrupt driven, thus, to some extent, it can simulate multithreading:

    Code:
    void ProcessData(){ 
     printf("...processing...\n");
     }
    
    void AddData(){ 
     printf("Data added.\n");
     system("pause");
     }
    
    
    
    int main(){
    
    int done = 0;
    
    do{ 
    
    
    while( !kbhit() ){
     ProcessData();
    }
    
    printf("The process has been interrupted.\n"
             "What would you like to do?\n\n"
             "A) Add data to be processed.\n"
             "B) Continue processing.\n"
             "C) Exit.\n\n    "); 
    
     switch(tolower(getch())){
      case 'a': AddData(); break;
      case 'c': done = 1; break;
      }
    
    }while( !done );
    
    
     return 0;
    }
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    145
    I know Sebastiani, but I was just wondering if I could do it this other way, instead of multithreading.
    Thanks.
    "Um...well..."
    -Kyoto Oshiro

  5. #5
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    In the future when everyone has at least a P4 with hyperthreading (or dual procs) you might be able to do it... but not now. The closest you can come right now is multithreading.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 01:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM