Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CSEP 545: Cache Algorithm Implementation, Slides of Business Administration

The implementation of a cache algorithm using c language. It includes functions such as start(), read(), write(), commit(), and abort(). The cache algorithm manages cache entries, disk reads and writes, and transaction management.

Typology: Slides

2012/2013

Uploaded on 07/29/2013

divit
divit 🇮🇳

4.2

(18)

141 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
lastTrans = 1;
...
int start()
{
if (lastTrans < 0) return -1
else
{lastTrans = -(++lastTrans);
return lastTrans;
}
}
As background to review the solution
7/23/2013 CSEP 545
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download CSEP 545: Cache Algorithm Implementation and more Slides Business Administration in PDF only on Docsity!

lastTrans = 1; ... int start() { if (lastTrans < 0) return - else { lastTrans = -(++lastTrans); return lastTrans; } }

• As background to review the solution

7/23/2013 CSEP 545 Docsity.com

int read(int blockAddr, int tId, int block) { / find the cache element e containing the block whose disk address is blockAddr / if (there is such a cache element e) { / the disk block at blockAddr is in cache / Cache(e).tId = tId; block = &Cache(e).newBlock; / &Cache(e).newBlock = address of Cache(e).newBlock / return 0; } else { / pick a cache entry e, where Cache(e).tId = 0. If there is no such entry, then return -1 */ diskRead(blockAddr, &Cache(e).oldBlock); Cache(e).newBlock = Cache(e).oldBlock; block = &Cache(e).newBlock; Cache(e).blockAddr = blockAddr Cache(e).tId = tId; return 0; }

}

int commit(int tId) { for (each cache entry e where Cache(e).tId == tId) { status = diskWrite(Cache(e).blockAddr, &Cache(e).newBlock); Cache(e).tId = - tId; if (status == -1) { Abort(tId); return -1; } Cache(e).oldBlock = Cache(e).newBlock }; for (each cache entry e where Cache(e).tId == -tId) Cache(e).tId = 0; lastTrans = -lastTrans;

return 0; }

int abort(int tId) { for (all cache entries e, where Cache(e).tId == -tId) { repeat { status = diskWrite(Cache(e).blockAddr, &Cache(e).oldBlock) }until (status == 0); /* Of course, this will not terminate if diskWrite keeps failing, but ignore that issue */

Cache(e).newBlock = Cache(e).oldBlock; }; for (all cache entries e) { Cache(e).tId = 0 }; lastTrans = -lastTrans; return 0; }