Consider an ARMv8 computer that is running more than one thread of execution. The computer has certain resources that must not be accessed or modified by different threads at the same time. These resources could be peripheral devices or memory buffers and data structures that are accessible by any threads. This type of concurrency control is a general computer science problem. It is possible to protect a shared resource by implementing a lock function, which allows a thread request ownership of the resource. An unlock function is necessary to allow software to release the lock. A simple lock system could be implemented using a variable in memory that can contain one of two values, LOCKED and, UNLOCKED. The action is to first read the value from memory, and if the lock is UNLOCKED then the value can be updated to LOCKED and written back to memory. This method is vulnerable to another thread modifying the value in memory in between the first read and the write-back of the new value. The instruction set has two instructions, LDXR and STXR, for generating an exclusive access to a memory location. Whenever an address is read using a Load Exclusive instruction, it is marked as being for an exclusive access. If an address marked as exclusive is written to using a Store Exclusive instruction, it clears the exclusive status. A flag is set if the contents of that address have been changed since the last time it was read. This enables software to detect if another thread has placed a lock on the resource. The syntax of the exclusive load is similar to a regular load: LDXR Xt, [Xn] The exclusive store instruction return an extra parameter that indicates if the store operation was successfully based on the exclusive monitor status. STXR Ws, Xt, [Xn] If the memory is not changed by another thread, the store updates the memory, and register Ws returns zero. If the memory is changed by another thread, the exclusive store does not update the memory, and register Ws returns a nonzero value. The following C++ program uses two functions to LOCK and UNLOCK a resource. lock(mem_addr); shared_var = math(shared_var, new_data); unlock(mem_addr);   Write two macros in ARMv8 assembly code to implement the lock(mem_addr) and unlock(mem_addr). The lock function should loop until the resource is available, then a LOCK can be placed and the execution continues to the next function. Assume that the memory address is in register X0, and use -1 in memory to indicate LOCKED and 0 for UNLOCKED.

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

Consider an ARMv8 computer that is running more than one thread of execution. The computer has certain resources that must not be accessed or modified by different threads at the same time. These resources could be peripheral devices or memory buffers and data structures that are accessible by any threads.

This type of concurrency control is a general computer science problem. It is possible to protect a shared resource by implementing a lock function, which allows a thread request ownership of the resource. An unlock function is necessary to allow software to release the lock.

A simple lock system could be implemented using a variable in memory that can contain one of two values, LOCKED and, UNLOCKED. The action is to first read the value from memory, and if the lock is UNLOCKED then the value can be updated to LOCKED and written back to memory. This method is vulnerable to another thread modifying the value in memory in between the first read and the write-back of the new value.

The instruction set has two instructions, LDXR and STXR, for generating an exclusive access to a memory location. Whenever an address is read using a Load Exclusive instruction, it is marked as being for an exclusive access. If an address marked as exclusive is written to using a Store Exclusive instruction, it clears the exclusive status. A flag is set if the contents of that address have been changed since the last time it was read. This enables software to detect if another thread has placed a lock on the resource.

The syntax of the exclusive load is similar to a regular load:
LDXR Xt, [Xn]
The exclusive store instruction return an extra parameter that indicates if the store operation was successfully based on the exclusive monitor status.
STXR Ws, Xt, [Xn]
If the memory is not changed by another thread, the store updates the memory, and register Ws returns zero. If the memory is changed by another thread, the exclusive store does not update the memory, and register Ws returns a nonzero value.

The following C++ program uses two functions to LOCK and UNLOCK a resource.

lock(mem_addr);
shared_var = math(shared_var, new_data);
unlock(mem_addr);

 

Write two macros in ARMv8 assembly code to implement the lock(mem_addr) and unlock(mem_addr). The lock function should loop until the resource is available, then a LOCK can be placed and the execution continues to the next function. Assume that the memory address is in register X0, and use -1 in memory to indicate LOCKED and 0 for UNLOCKED.

Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Race Condition
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