Tuesday, May 24, 2011

Lock on a tree

Given an n-ary tree of resources arranged hierarchically. A process needs to lock a resource node in order to use it. But a node cannot be locked if any of its descendant or ancestor is locked. You are supposed to:

write the structure of node
write codes for

* Islock()- returns true if a given node is locked and false if it is not
* Lock()- locks the given node if possible and updates lock information
* Unlock()- unlocks the node and updates information.

2 comments:

  1. Looks like this reduces to a lock on the root node because every lock depends on being able to lock the root as the ultimate ancestor.

    Am I missing something?

    ReplyDelete