logo

Crowdly

Browser

Add to Chrome

For this question, refer to the following code: mutex_t m; int slot = -1; int ...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

For this question, refer to the following code:

mutex_t m;

int slot = -1;

int array[2] = { 0, 0 }; // initialize to 0, 0 contents

function1() {

mutex_acquire(&m);

slot++;

int tid = get_counter();

array[slot] = tid;

mutex_release(&m);

}

Assume that get_counter() has its own internal locking (not shown), and will return 1 when first called, and 2 when called next, etc. Assume that function1() is called by two threads at roughly the same time. What are the final contents of the array?

0%
0%
0%
0%
0%
More questions like this

Want instant access to all verified answers on moodle31.upei.ca?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome