C++ WIN32: Short multitasking example
- by Con Current
I searched for examples on how to create a simple multithreaded app that does something similar to this:
#include <iostream>
using namespace std;
int myConcurrentFunction( )
{
while( 1 )
{
cout << "b" << endl;
}
}
int main( )
{
// Start a new thread for myConcurrentFunction
while( 1 )
{
cout << "a" << endl;
}
}
How can I get the above to output a and b "randomly" by starting a new thread instead of just calling myConcurrentFunction normally?
I mean: What is the minimal code for it? Is it really only one function I have to call? What files do I need to include?
I use MSVC 2010, Win32