Click to See Complete Forum and Search --> : running two codes at the same time


Pitufo
June 4th, 2009, 04:07 PM
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.

MrViggy
June 4th, 2009, 05:02 PM
Code execution in a thread is sequential. In your example, you would read the mouse data, then read the other device data. It will not happen at the same time.

If you need to happen "at the same time", then you'll need to look into using multiple threads.

Viggy

Pitufo
June 4th, 2009, 05:08 PM
how can i do that...can you give me an example...or tell me how to find this please...

nuzzle
June 4th, 2009, 11:44 PM
how can i do that...can you give me an example...or tell me how to find this please...

Here's a start maybe,

http://weblogs.asp.net/kennykerr/archive/2007/12/11/parallel-programming-with-c-a-new-series.aspx

Note that for two tasks to run in parallel in real time you need a computer with many processors or a processor with multiple cores or both. Otherwise the tasks will be executed serially even if you use multiple threads.

wigga
June 8th, 2009, 07:37 AM
We can give better advice with more information. What do you want todo, axactly. Are u sure its even neccesary todo these things at the same time?