This will be followed by the two threads sending their own unique outputs to the console. Note the the main thread will output “Press a key to finish”. If everything compiles correctly, test the program by pulling down the Debug menu and selecting the Start Debugging menu item. Join up the two worker threads back to the main threadīuild the program by pulling down the Build menu and selecting Build Solution menu item. The new main.cpp file will now be open and ready to add code.Īdd the following source code to the main.cpp file: When finished, click the Add button as shown below. In the Add New Item dialog box, highlight the C++ File (.cpp) selection and then give a new name: main.cpp for the new file. Add a new file to the project by right-clicking on the Source Files category, select Add and then select New Item… as shown below: Navigate to the Solution Explorer (if you do not see the Solution Explorer, locate it on View menu). The Visual Studio development environment will appear as shown below. In the next step of the Wizard, select Console Application and then check the box for Empty Project. Once you are ready click the OK button:īecause this is a Console application, the following Wizard will launch. Give a new name for the project: MultithreadingDemo1 and select a suitable location for your project as shown below. Pull down the File menu and select the New Project menu item.įor this new project, select the Visual C++ category and then Win32 Console Application. To get started, run Microsoft Visual Studio 2012 or 2013. If you have never programmed in C++ using MS Visual Studio, you may consider going through the tutorial linked here before continuing with the example below. In this example we will create a simple multi-threaded C++ program using C++11 style threads. Multithreading Example in C++11 using Visual Studio
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |