Due: November 25, 2008
multiply()
{
unsigned i, j, k;
for(i = 0; i < 1024; i++)
for(j = 0; j < 1024; j++)
for(k = 0; k < 1024; k++)
c[i][j] += a[i,k] * b[k,j];
}
Assume that the binary for executing this function fits in one page, and the stack also fits in one page. Assume further that an integer requires 4 bytes for storage. Compute the number of TLB misses if the page size is 4096 and the TLB has 8 entries with a replacement policy consisting of LRU.
s1.wait; a++; s2.wait; v++; s2.signal; s1.signal;(s1, s2 are semaphores). Now, consider two threads running this fragment of code simultaneously, can there be a deadlock? Why, or why not?
if(a > 0)
s1.wait;
else
s2.wait;
b++;
s3.wait;
if(b < 0 && a <= 0)
s1.wait;
else if(b >= 0 && a > 0)
s2.wait;
else
s4.wait;
a++;
s4.signal;
s3.signal;
s2.signal;
s1.signal;
s1, s2, s3 and s4 are semaphores. Now, consider two threads running this fragment of code simultaneously, can there be a deadlock? Why, or why not?