I want to run two voids at once, aka multithreading, for a program that I'm making. I want to make a program that has a timer, and your supposed to cin an answer to a question.
I just need to know how to run two voids exactly at the same time, thanks!
#include <*stuff*>
usingnamespace std;
void a()
{
Beep(1000,1000);
}
void b()
{
int a;
cin>>a;
}
int main()
{
a();//I need to run these two
b();//lines at the same time
return 0;
}
They're called functions not voids, You put void there to tell the compiler that a function doesn't return a value.
For concurrent operations you could use std::thread (only available since c++11) http://www.cplusplus.com/reference/thread/thread/
There is no guarantee that the two threads will run concurrently as it may be faster to run each function one after the other without starting up a new thread(s) (in your example it almost certainly would be faster to not use threads)