subject
Computers and Technology, 20.02.2020 02:03 Yuii

A file named pthread-data-sharing-mutex. cpp
has been provided to you in the same project.

Compile the program and execute it several times, at least 10. Make sure to pay close attention to the output that the program produces.

Create a Word or Google Docs document.

In this document, answer the following questions about the program’s behavior:

1. What does it do?

2. What output does it produce?

3. Examine the program code carefully. Is the program functioning correctly?

4. If you do not think that the program is working correctly, describe why?

Include one screenshot of the program’s output. Your choice.

#include
#include

int count;

void* myFunction(void* arg)
{
int actual_arg = *((int*) arg);

for(unsigned int i = 0; i < 10; ++i) {
count++;
std::cout << "Thread #" << actual_arg << " count = " << count << std::endl;
}

pthread_exit(NULL);
}

int main()
{
int rc[2];
pthread_t ids[2];
int args[2];

count = 0;
for(unsigned int i = 0; i < 2; ++i) {
args[i] = i;
rc[i] = pthread_create(&ids[i], NULL, myFunction, (void*) &args[i]);
}

for(unsigned int i = 0; i < 2; ++i) {
pthread_join(ids[i], NULL);
}

std::cout << "Final count = " << count << std::endl;
pthread_exit(NULL);
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 13:00
Which part of the cpu accepts data?
Answers: 1
question
Computers and Technology, 22.06.2019 17:40
Gabe wants to move text from one document to another document. he should copy the text, paste the text, and open the new document highlight the text, select the cut command, move to the new document, make sure the cursor is in the correct location, and select the paste command select the save as command, navigate to the new document, and click save highlight the text, open the new document, and press ctrl and v
Answers: 1
question
Computers and Technology, 22.06.2019 23:00
Is an attack that relies on guessing the isns of tcp packets
Answers: 2
question
Computers and Technology, 23.06.2019 13:30
Drag the tiles to the correct boxes to complete the pairs. match the errors with their definitions. #name #value #ref when a formula produces output that is too lengthy to fit in the spreadsheet cell arrowright when you enter an invalid cell reference in a formula arrowright when you type text in cells that accept numeric data arrowright when you type in a cell reference that doesn’t exist arrowright reset next
Answers: 1
You know the right answer?
A file named pthread-data-sharing-mutex. cpp
has been provided to you in the same project.
Questions
question
Mathematics, 22.06.2021 19:10
question
Mathematics, 22.06.2021 19:10
Questions on the website: 13722363