Menu

[Solved]Consider Following Program Int Count 0 Shared Variable Since Global Void Twiddledee Int 0 Q37239225

Consider the following program:

int count = 0; //shared variable since its global
void twiddledee() {
int i=0; //for part b this will be global and shared
for (i=0; i<2; i++) {
count = count * count; //assume count read from memory once
}
}
void twiddledum() {
int i=0; // for part b, this will be global and shared
for(i=0; i<2; i++) {
count = count – 1; }int i=0;
}
}
void main() {
thread_fork(twiddledee);
thread_fork(twiddledum);
print count;
}

a) What are all the values that could be printed in main? (5points)
b) Repeat part 1 considering that i is also a shared variable(Bonus 3 points –
tricky!)
c) Describe a potential schedule of execution that will result inthe value printed out
being equal to 0. Assuming there is only one CPU core, clearlyspecify when the
transitions between the Ready and Running states occurs for eachthread in this
execution. (3 points)

Expert Answer


Answer to Consider the following program: int count = 0; //shared variable since its global void twiddledee() { int i=0; //for pa… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *