Given a world map in the form of a Generic M-ary Tree consisting of N nodes and an array of queries[], the task is to implement the functions Lock, Unlock and Upgrade for the given tree. For each query in queries[], the functions return true when the operation is performed successfully, otherwise, it returns false. The functions are defined as:   X: Name of the node in the tree and will be unique uid: User Id for the person who accesses node X 1. Lock(X, uid): Lock takes exclusive access to the subtree rooted. - Once Lock(X, uid) succeeds, then lock(A, any user) should fail, where A is a descendant of X. - Lock(B. any user) should fail where X is a descendant of B. - Lock operation cannot be performed on a node that is already locked. 2. Unlock(X, uid): To unlock the locked node. - The unlock reverts what was done by the Lock operation. - It can only be called on same and unlocked by same uid. 3. UpgradeLock(X, uid): The user uid can upgrade their lock to an ancestor node. - It is only possible if any ancestor node is only locked by the same user uid. - The Upgrade should fail if there is any node that is locked by some other uid Y below. Examples: Input: N = 7, M = 2, nodes = [‘World’, ‘Asia’, ‘Africa’, ‘China’, ‘India’, ‘SouthAfrica’, ‘Egypt’],   queries =  [‘1 China 9’, ‘1 India 9’, ‘3 Asia 9’, ‘2 India 9’, ‘2 Asia 9’] Output: true true true false true Input: N = 3, M = 2, nodes = [‘World’, ‘China’, ‘India’],   queries =  [‘3 India 1’, ‘1 World 9’] Output: false true The same question with its Java and Python code can be found on the GFG platform at https://www.geeksforgeeks.org/tree-of-space-locking-and-unlocking-n-ary-tree/ Please let me know the solution to the following problem: Let's say you are running the lock/unlock on a multi-core machine. Now you want to let multiple threads run lock() simultaneously. As we know, locking a node has multiple validations inside. Doing lock on two nodes will definitely cause a race condition. How to solve this race condition? In short, how do make the lock() function thread safe? There are a few contraints that need to be followed while solving the problem: - Multiple threads running it simultaneously shouldn't affect the correctness. - Note that the critical sections should be granular. - Don't create any big transaction blocks that will make parallelism suffer. - making the function synchronized is not allowed but we can use upgradelock - we cannot use an inbuilt mutex, semaphores, synchronize. Give me the "detail" approaches (no need for the code) to the above problem with proper reasoning.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Given a world map in the form of a Generic M-ary Tree consisting of N nodes and an array of queries[], the task is to implement the functions Lock, Unlock and Upgrade for the given tree. For each query in queries[], the functions return true when the operation is performed successfully, otherwise, it returns false.

The functions are defined as:
 
X: Name of the node in the tree and will be unique
uid: User Id for the person who accesses node X

1. Lock(X, uid): Lock takes exclusive access to the subtree rooted.
- Once Lock(X, uid) succeeds, then lock(A, any user) should fail, where A is a descendant of X.
- Lock(B. any user) should fail where X is a descendant of B.
- Lock operation cannot be performed on a node that is already locked.

2. Unlock(X, uid): To unlock the locked node.
- The unlock reverts what was done by the Lock operation.
- It can only be called on same and unlocked by same uid.

3. UpgradeLock(X, uid): The user uid can upgrade their lock to an ancestor node.
- It is only possible if any ancestor node is only locked by the same user uid.
- The Upgrade should fail if there is any node that is locked by some other uid Y below.

Examples:
Input: N = 7, M = 2, nodes = [‘World’, ‘Asia’, ‘Africa’, ‘China’, ‘India’, ‘SouthAfrica’, ‘Egypt’],  
queries =  [‘1 China 9’, ‘1 India 9’, ‘3 Asia 9’, ‘2 India 9’, ‘2 Asia 9’]
Output: true true true false true

Input: N = 3, M = 2, nodes = [‘World’, ‘China’, ‘India’],  
queries =  [‘3 India 1’, ‘1 World 9’]
Output: false true

The same question with its Java and Python code can be found on the GFG platform at https://www.geeksforgeeks.org/tree-of-space-locking-and-unlocking-n-ary-tree/

Please let me know the solution to the following problem:

Let's say you are running the lock/unlock on a multi-core machine. Now you want to let multiple threads run lock() simultaneously.
As we know, locking a node has multiple validations inside. Doing lock on two nodes will definitely cause a race condition.
How to solve this race condition?
In short, how do make the lock() function thread safe?

There are a few contraints that need to be followed while solving the problem:
- Multiple threads running it simultaneously shouldn't affect the correctness.
- Note that the critical sections should be granular.
- Don't create any big transaction blocks that will make parallelism suffer.
- making the function synchronized is not allowed but we can use upgradelock
- we cannot use an inbuilt mutex, semaphores, synchronize.

Give me the "detail" approaches (no need for the code) to the above problem with proper reasoning.

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Not satisfied with your answer, please extend your answer

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Hash Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education