logo

Crowdly

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++;

mutex_release(&m);

int tid = get_counter();

mutex_acquire(&m);

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?

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!