After Hours Academic

Question 7: Single access blog

Jesse has built an blog hosting service where user's can write and read blogs. Jesse wants to guarantee that a recruiter will always see the most recent and consistent (i.e., not an in-progress) version of a blog. That is, Jesse wants to avoid scenario wherein Gus is editing his blog and Hank sees Gus's half-edited blog. So Jesse only allows a single user to access any given blog at any given point of time. He implemented this by using a lock for each blog that a user has to acquire before accessing the blog. Jesse's boss, Walter, is not too happy with this solution because this also disallows two users to read a blog simultaneously.

Can you suggest a mechanism that Jesse can use to address Walter's concern?

Solution coming up in the next post!

Solution for conferencing researchers:

This is a variant of the dining philosophers problem. There are different solutions to this problem. The one I prefer (for its simplicity) uses resource ordering.

If we can impose an ordering on the resources (bowl, fork, knife, notepad, pen) and require the researchers to acquire locks on the resources in order, we can avoid deadlocks. In this scenario, we need the following orders:

  1. bowl, fork, knife
  2. notepad, pen

Researchers that want to eat need to acquire bowl, fork, and knife in that order. If they are not able to acquire them in order, they are supposed to give up trying to eat. This ensures that one of the researchers (the one that acquired the bowl first) would be able to acquire all the resources and eat. This researcher can then release the locks on all the three, and another researcher would be able to acquire all three.

Similarly, if a researcher wants to think, they need to acquire notepad and pen in that order. Only one of the researcher (the one who acquires the notepad first) would be able to acquire both and think.

There is the question of what if a researcher dies (morbid, I know, but we aren't actually talking about human researchers here, just some threads and processes :)) while holding a resource. Well, that requires using fault tolerant locks.

#concurrency #qna