✅ 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?