running two codes at the same time

Discussion in 'C' started by Andres, Jun 4, 2009.

  1. Andres

    Andres New Member

    Joined:
    Jul 22, 2008
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Is there a way to run two codes in a program at the same time. For example, I have this program that is getting information from two things.
    Lets just say something like the following:

    cin>>data from mouse;
    cin>>data from other device;

    Does the program get capture receive the information from top to bottom or does it get both info at the same time. My problem is that I am not sure that the info is being processed at the same time. I need to be sure since I want it to be in real time. Can someone please help me please. Is there a code to process both information at the same time.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    You can only run two operations at the same time if you have more than one CPU.
    However there are approximations. Look up "multithreading". It's a lot of fun.
    Or if you prefer to keep to a single thread, you could check one for input, then check the other, then do whatever other stuff the program is supposed to do, and so on.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice