Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. (100 points) Create multiple threads to do tasks simultaneously. Read the C++ thread class introduction at https://en.cppreference.com/w/cpp/thread/thread then run the following code. //Example #include

image text in transcribedimage text in transcribed

1. (100 points) Create multiple threads to do tasks simultaneously. Read the C++ thread class introduction at https://en.cppreference.com/w/cpp/thread/thread then run the following code. //Example \#include \#include \#include using namespace std; // The function we want to execute on the new thread. void task1(string msg) \{ \} seut "task1 says: " msg; int main( ) \{ // Constructs the new thread and runs it. Does not block execution. thread t1(task1, "Hello"); // Do other things... // Makes the main thread wait for the new thread to finish execution, therefore blocks its own execution. t, join (; return ; \} (40 points) modify the example code and create two threads. One thread is to calculate the sum of integers from 1 to 10 and other thread is to calculate the factorial 10!. Display the results on screen. Source code and screenshot of running results are shown below

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxiv Special Issue On Database And Expert Systems Applications Lncs 9510

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Hendrik Decker ,Lenka Lhotska ,Sebastian Link

1st Edition

366249213X, 978-3662492130

More Books

Students also viewed these Databases questions