Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Is this a single process? Are there multiple address spaces being used within th

ID: 3595473 • Letter: I

Question

Is this a single process?
Are there multiple address spaces being used within the process(es)?
What is different about each thread if anything? What exactly is it doing and the expected output.

//CSC313 Operating Systems

#include <iostream>
#include <vector>
#include <thread>

using namespace std;

int addthreads = 0;

void squarenum(int x) {

addthreads += x * x * x;

}

int main() {

vector<thread> septhread;

for (int i = 1; i <= 6; i++){

septhread.push_back(thread(&squarenum, i));

}

for (auto& th : septhread){

th.join();

}

cout << "Your answer = " << addthreads << endl;

system("pause");

return 0;

}

Explanation / Answer

This is a single process application, but it is multithreaded. There are total 7 threads will be created.

main thread is auto created when the process runs. main thread is creating 6 more threads using thread API. For each thread seperate address space will be created for stack creation.

main thread is going to halt state by th.join api before returning, that means it is waiting for all thread execution to complete.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote