subject

Assume we have two threads each running its own code but sharing a variable counter from their parent shared data. Also, assume a uniprocessor system is used. Counter=0

//Thread 1 //Thread 2
for (i=0; i< 10; i++)
{
counter = counter +1;
}
for (j=0; j < 10, J++)
{
counter = counter + 1;
}

1. Prove that there is a race condition in the above example. (10 marks)
2. What is the possible maximum value of variable counter when both threads terminate normally? Show how you calculated that value. (4 marks)
3. Solve the race condition problem above by modifying the code using the Test-and-Set instruction. (6 marks)

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 13:50
The instruction ishl (shift left integer) exists in jvm but not in ijvm. it uses the top two values on the stack, replacing the two with a single value, the result. the sec- ond-from-top word of the stack is the operand to be shifted. its content is shifted left by a value between 0 and 31, inclusive, depending on the value of the 5 least signifi- cant bits of the top word on the stack (the other 27 bits of the top word are ignored). zeros are shifted in from the right for as many bits as the shift count. the opcode for ishl is 120 (0x78).a. what is the arithmetic operation equivalent to shifting left with a count of 2? b. extend the microcode to include this instruction as a part of ijv.
Answers: 1
question
Computers and Technology, 22.06.2019 15:00
The three logical operators used to write compound conditions are "and," "or," and "not." a: true b: false
Answers: 2
question
Computers and Technology, 22.06.2019 18:30
Which of these options are the correct sequence of actions for content to be copied and pasted? select content, click the copy button, click the paste button, and move the insertion point to where the content needs to be inserted. click the copy button, select the content, move the insertion point to where the content needs to be inserted, and click the paste button. select the content, click the copy button, move the insertion point to where the content needs to be inserted, and click the paste button. select the content, move the insertion point to where the content needs to be inserted, click the copy button, and click the paste button.
Answers: 3
question
Computers and Technology, 23.06.2019 09:30
The place where the extended axis of the earth would touch the celestial sphere is called the celestial
Answers: 1
You know the right answer?
Assume we have two threads each running its own code but sharing a variable counter from their paren...
Questions
question
Social Studies, 07.07.2019 08:10
Questions on the website: 13722360