SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
Concurrency Control in
Distributed Systems
Definition, Working & Algorithms
Definition
• Concurrent means happening at the same time.
Concurrency, concurrent, or concurrence may refer to:
• Concurrency (computer science), the property of program,
algorithm, or problem decomposition into order-independent or
partially-ordered units without affecting the outcome.
• Concurrent computing, the overlapping execution of multiple
interacting computational tasks.
Objectives
Throughput: Number of transactions processed per unit time
• E.g. 1 million transactions per second
Maximum transaction throughput (work perform) while preventing
interference among multiple users. |Efficient use of resources
Advantages
• Waiting time will be decreased.
• Response time will decrease.
• Resource utilization will increase.
• System performance & Efficiency is increased.
Main problems in using Concurrency
The problems which arise while using concurrency are as follows
• Updates will be lost − One transaction does some changes and another
transaction deletes that change. One transaction nullifies the updates of
another transaction.
• Uncommitted Dependency or dirty read problem − One variable has
updated in one transaction, at the same time another transaction has
started and deleted the value of the variable there the variable is not
getting updated or committed that has been done on the first transaction
this gives us false values or the previous values of the variables this is a
major problem.
• Inconsistent retrievals − One transaction is updating multiple different
variables, another transaction is in a process to update those variables,
and the problem occurs is inconsistency of the same variable in different
instances.
Algorithms (Concurrency Control Mechanisms)
1. Two-Phase Locking(2PL) algorithms
Lock guaranties exclusive use of data items to a current
transaction. It first accesses the data items by acquiring a lock,
after completion of the transaction it releases the lock.
2. Timestamps ordering(T/O) algorithms
Whatever transaction we are doing it stores the starting time of
the transaction and denotes a specific time.
3. Optimistic algorithms
It is based on the assumption that conflict is rare and it is more
efficient to allow transactions to proceed without imposing
delays to ensure serializability.
Locking
• R/W locks
• The lock Manager
• Responsible to maintain the list of locked files
• Shared Locks
• Transaction can read only the data item values
• Exclusive Locks
• Used for both read and write data item values
Two-Phase Locking
Strict Two-Phase Locking
Two-Phase locking can lead to deadlocks
• If two processes each try to acquire the same pair of locks but in the
opposite order, a deadlock may result.
• Hold and wait cycle.
• Deadlock detection
• T. sec / Timeout scheme can be used.
Optimistic Concurrency Control
• Second Approach to handling multiple transactions at the same time
is optimistic concurrency control
• The idea behind this technique is surprisingly simple: just go ahead
and do whatever you want to, without paying attention to what
anybody else is doing.
• If there is a problem, worry about it later.
Optimistic Concurrency Control
• What Optimistic concurrency control does is:
• Keep track of which files have been read and written
• At the point of committing, it checks all other transactions to see if any of its
files have been changed since the transaction started.
• If so, the transaction is aborted.
• If not, it is committed.
Optimistic Concurrency Control
• Optimistic Concurrency control fits best with the implementation
based on private workspaces.
• That way, each transaction changes its files privately, without
interference from the others.
• At the end, the new files are either committed or released.
Advantages / Disadvantages of (OCC)
Advantages:
• Deadlock Free
• Maximum parallelism
Disadvantages:
• it may fail, in which case the transaction has to be run all over again
• Under condition of heavy load the probability of failure may go up
Program Demo
Talk is cheap, show
me the code.
Summary(Mind-map)
Any question?
References
• Philip A. Bernstein, Vassos Hadzilacos, Nathan Goodman (1987): Concurrency Control and Recovery in Database Systems (free PDF
download), Addison Wesley Publishing Company, 1987, ISBN 0-201-10715-5
• Concurrency Control from tutorialspoint.com
• wikipedia.org/wiki/Concurrency_control
• Nancy Lynch, Michael Merritt, William Weihl, Alan Fekete (1993): Atomic Transactions in Concurrent and Distributed Systems , Morgan
Kaufmann (Elsevier), August 1993, ISBN 978-1-55860-104-8, ISBN 1-55860-104-X
• Yoav Raz (1992): "The Principle of Commitment Ordering, or Guaranteeing Serializability in a Heterogeneous Environment of Multiple
Autonomous Resource Managers Using Atomic Commitment." (PDF), Proceedings of the Eighteenth International Conference on Very Large
Data Bases (VLDB), pp. 292-312, Vancouver, Canada, August 1992. (also DEC-TR 841, Digital Equipment Corporation, November 1990)

More Related Content

PPTX
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
PPT
Query Decomposition and data localization
PPTX
Distributed dbms architectures
PDF
Ddb 1.6-design issues
PPTX
Deadlock ppt
PPTX
Lecture 2 - Asynchrnous and Synchronous Computation & Communication.pptx
PPTX
PPT
Distributed Systems
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Query Decomposition and data localization
Distributed dbms architectures
Ddb 1.6-design issues
Deadlock ppt
Lecture 2 - Asynchrnous and Synchronous Computation & Communication.pptx
Distributed Systems

What's hot (20)

PDF
Parallel and Distributed Computing chapter 1
PPTX
Query processing in Distributed Database System
PDF
Lecture 03 - Synchronous and Asynchronous Communication - Concurrency - Fault...
PPTX
Transactions and Concurrency Control
PPTX
Concurrency control
PDF
Concurrency
PPTX
Common Object Request Broker Architecture
PDF
Cs2303 theory of computation all anna University question papers
PPT
Deadlock Detection
DOC
Authentication Models
PPTX
Sleeping barber problem
PPT
Multi core-architecture
PPT
Client Centric Consistency Model
PPTX
Concurrency control
PPT
Chapter17
PPTX
Database System Architectures
PPT
Two phase commit protocol in dbms
PPTX
Server system architecture
PPTX
Multivector and multiprocessor
PPTX
Multithreading models.ppt
Parallel and Distributed Computing chapter 1
Query processing in Distributed Database System
Lecture 03 - Synchronous and Asynchronous Communication - Concurrency - Fault...
Transactions and Concurrency Control
Concurrency control
Concurrency
Common Object Request Broker Architecture
Cs2303 theory of computation all anna University question papers
Deadlock Detection
Authentication Models
Sleeping barber problem
Multi core-architecture
Client Centric Consistency Model
Concurrency control
Chapter17
Database System Architectures
Two phase commit protocol in dbms
Server system architecture
Multivector and multiprocessor
Multithreading models.ppt
Ad

Similar to Concurrency Control in Distributed Systems.pptx (20)

PPTX
Concurrency control
PPTX
Concurrent control
DOC
Concurrency control
PPTX
DBMS Session 6 Transactions Management and Concurrency Control.pptx
PPTX
Advanced Operating Systems- Synchronization primitives in os
PDF
Concurrency control
PPTX
Optimistic concurrency control in Distributed Systems
PPT
Database concurrency control & recovery (1)
PDF
Advanced Database Chapter 4.pdf shnsbxlajmndm woweosmkl m,xcnkl C NOOxcx xcbnxc
PPT
5-Chapter Five - Concurrenc.ppt
PPTX
L12 Concurrent Programming
PPTX
Concurrency control
PDF
Module 5 part-2 concurrency control in dbms
PDF
CONCURRENCY CONTOL notes.pdf
PPTX
Chapter_NINE_Concurrency_Control_DBMS.pptx
PPTX
2 con control
PPTX
Transaction management transparencies
PDF
LECT CONCURRENCY………………..pdf document or power point
PPTX
Databaseconcurrencycontroltechniquepresentations
PPT
concurrency-control
Concurrency control
Concurrent control
Concurrency control
DBMS Session 6 Transactions Management and Concurrency Control.pptx
Advanced Operating Systems- Synchronization primitives in os
Concurrency control
Optimistic concurrency control in Distributed Systems
Database concurrency control & recovery (1)
Advanced Database Chapter 4.pdf shnsbxlajmndm woweosmkl m,xcnkl C NOOxcx xcbnxc
5-Chapter Five - Concurrenc.ppt
L12 Concurrent Programming
Concurrency control
Module 5 part-2 concurrency control in dbms
CONCURRENCY CONTOL notes.pdf
Chapter_NINE_Concurrency_Control_DBMS.pptx
2 con control
Transaction management transparencies
LECT CONCURRENCY………………..pdf document or power point
Databaseconcurrencycontroltechniquepresentations
concurrency-control
Ad

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PDF
01-Introduction-to-Information-Management.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Cell Structure & Organelles in detailed.
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Classroom Observation Tools for Teachers
01-Introduction-to-Information-Management.pdf
RMMM.pdf make it easy to upload and study
Final Presentation General Medicine 03-08-2024.pptx
Supply Chain Operations Speaking Notes -ICLT Program
Microbial diseases, their pathogenesis and prophylaxis
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
O7-L3 Supply Chain Operations - ICLT Program
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Module 4: Burden of Disease Tutorial Slides S2 2025
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Cell Structure & Organelles in detailed.
Pharmacology of Heart Failure /Pharmacotherapy of CHF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE

Concurrency Control in Distributed Systems.pptx

  • 1. Concurrency Control in Distributed Systems Definition, Working & Algorithms
  • 2. Definition • Concurrent means happening at the same time. Concurrency, concurrent, or concurrence may refer to: • Concurrency (computer science), the property of program, algorithm, or problem decomposition into order-independent or partially-ordered units without affecting the outcome. • Concurrent computing, the overlapping execution of multiple interacting computational tasks.
  • 3. Objectives Throughput: Number of transactions processed per unit time • E.g. 1 million transactions per second Maximum transaction throughput (work perform) while preventing interference among multiple users. |Efficient use of resources Advantages • Waiting time will be decreased. • Response time will decrease. • Resource utilization will increase. • System performance & Efficiency is increased.
  • 4. Main problems in using Concurrency The problems which arise while using concurrency are as follows • Updates will be lost − One transaction does some changes and another transaction deletes that change. One transaction nullifies the updates of another transaction. • Uncommitted Dependency or dirty read problem − One variable has updated in one transaction, at the same time another transaction has started and deleted the value of the variable there the variable is not getting updated or committed that has been done on the first transaction this gives us false values or the previous values of the variables this is a major problem. • Inconsistent retrievals − One transaction is updating multiple different variables, another transaction is in a process to update those variables, and the problem occurs is inconsistency of the same variable in different instances.
  • 5. Algorithms (Concurrency Control Mechanisms) 1. Two-Phase Locking(2PL) algorithms Lock guaranties exclusive use of data items to a current transaction. It first accesses the data items by acquiring a lock, after completion of the transaction it releases the lock. 2. Timestamps ordering(T/O) algorithms Whatever transaction we are doing it stores the starting time of the transaction and denotes a specific time. 3. Optimistic algorithms It is based on the assumption that conflict is rare and it is more efficient to allow transactions to proceed without imposing delays to ensure serializability.
  • 6. Locking • R/W locks • The lock Manager • Responsible to maintain the list of locked files • Shared Locks • Transaction can read only the data item values • Exclusive Locks • Used for both read and write data item values
  • 9. Two-Phase locking can lead to deadlocks • If two processes each try to acquire the same pair of locks but in the opposite order, a deadlock may result. • Hold and wait cycle. • Deadlock detection • T. sec / Timeout scheme can be used.
  • 10. Optimistic Concurrency Control • Second Approach to handling multiple transactions at the same time is optimistic concurrency control • The idea behind this technique is surprisingly simple: just go ahead and do whatever you want to, without paying attention to what anybody else is doing. • If there is a problem, worry about it later.
  • 11. Optimistic Concurrency Control • What Optimistic concurrency control does is: • Keep track of which files have been read and written • At the point of committing, it checks all other transactions to see if any of its files have been changed since the transaction started. • If so, the transaction is aborted. • If not, it is committed.
  • 12. Optimistic Concurrency Control • Optimistic Concurrency control fits best with the implementation based on private workspaces. • That way, each transaction changes its files privately, without interference from the others. • At the end, the new files are either committed or released.
  • 13. Advantages / Disadvantages of (OCC) Advantages: • Deadlock Free • Maximum parallelism Disadvantages: • it may fail, in which case the transaction has to be run all over again • Under condition of heavy load the probability of failure may go up
  • 14. Program Demo Talk is cheap, show me the code.
  • 17. References • Philip A. Bernstein, Vassos Hadzilacos, Nathan Goodman (1987): Concurrency Control and Recovery in Database Systems (free PDF download), Addison Wesley Publishing Company, 1987, ISBN 0-201-10715-5 • Concurrency Control from tutorialspoint.com • wikipedia.org/wiki/Concurrency_control • Nancy Lynch, Michael Merritt, William Weihl, Alan Fekete (1993): Atomic Transactions in Concurrent and Distributed Systems , Morgan Kaufmann (Elsevier), August 1993, ISBN 978-1-55860-104-8, ISBN 1-55860-104-X • Yoav Raz (1992): "The Principle of Commitment Ordering, or Guaranteeing Serializability in a Heterogeneous Environment of Multiple Autonomous Resource Managers Using Atomic Commitment." (PDF), Proceedings of the Eighteenth International Conference on Very Large Data Bases (VLDB), pp. 292-312, Vancouver, Canada, August 1992. (also DEC-TR 841, Digital Equipment Corporation, November 1990)

Editor's Notes

  • #2: Greetings, Intro, and topic overview… Good Morning to all! This is M. Arshad and today, in this session we are going to talk about concurrency control in distributed systems.. i.e. First of all, we’ll also see what is Concurrency, Concurrency Control and objectives. Secondly, we’ll discuss different algorithms/ methods to tackle concurrency issues. Thirdly, implementing a locking algorithm in cpp to demonstrate the concept of concurrency control in real-world scenario. Then there will be a mind map summary. In the end, there will be a brief discussion session.
  • #3: Concurrency control refers to managing simultaneous access to shared resources in a distributed environment to ensure consistency and avoid conflicts between concurrent transactions. Now, When multiple transactions are executing simultaneously on different processors then some kind of mechanism is needed to keep out of them away, and that mechanism is called concurrency control. Concurrency Control deals with interleaved execution of more than one transaction. In information technology and computer science, especially in the fields of computer programming, operating systems, multiprocessors, and databases, concurrency control ensures that correct results for concurrent operations are generated, while getting those results as quickly as possible.
  • #4: Most high-performance transactional systems need to run transactions concurrently to meet their performance requirements. Thus, without concurrency control such systems can neither provide correct results nor maintain their databases consistently. If transactions are executed serially, i.e., sequentially with no overlap in time, no transaction concurrency exists. However, if concurrent transactions with interleaving operations are allowed in an uncontrolled manner, some unexpected, undesirable results may occur
  • #6: The main categories of concurrency control mechanisms are: Optimistic - Delay the checking of whether a transaction meets the isolation and other integrity rules (e.g., serializability and recoverability) until its end, without blocking any of its (read, write) operations ("...and be optimistic about the rules being met..."), and then abort a transaction to prevent the violation, if the desired rules are to be violated upon its commit. An aborted transaction is immediately restarted and re-executed, which incurs an obvious overhead (versus executing it to the end only once). If not too many transactions are aborted, then being optimistic is usually a good strategy. Pessimistic - Block an operation of a transaction, if it may cause violation of the rules, until the possibility of violation disappears. Blocking operations is typically involved with performance reduction. Semi-optimistic - Block operations in some situations, if they may cause violation of some rules, and do not block in other situations while delaying rules checking (if needed) to transaction's end, as done with optimistic.
  • #7: In this mechanism, When a process wants to read/write, it first apply lock on the file. Now, the lock manager maintains a lists of all the locked files and it’ll reject all the intends to lock the files that are already locked by another processor. So setting a lock on file keeps everyone else away from it and thus it ensures it’ll not change during the lifetime of the transaction. Now, this lock is usually acquired and released by the transaction system and not require any action by the programmer. If a read lock is set on a file then other read locks are permitted, therefore read lock is called as shared lock. Whereas a file is locked for writing no other locks of any kind is permitted, therefore write locks are called exclusive locks. #include <iostream> #include <omp.h> using namespace std; class BankAccount { private: int balance; omp_lock_t lock; // OpenMP lock for synchronization public: BankAccount(int initialBalance) : balance(initialBalance) { omp_init_lock(&lock); // Initializing the lock } void withdraw(int amount) { omp_set_lock(&lock); // Acquiring the lock if (balance >= amount) { balance -= amount; cout << "\tWithdrew Rs." << amount << ". Remaining balance: Rs." << balance << endl; } else { cout << "\n\tInsufficient funds" << endl; } omp_unset_lock(&lock); // Releasing the lock } ~BankAccount() { omp_destroy_lock(&lock); // Destroying the lock } }; // Function to simulate multiple withdrawals using OpenMP parallel sections void makeWithdrawals(BankAccount& account, int amount, int numWithdrawals) { #pragma omp parallel for for (int i = 0; i < numWithdrawals; ++i) { account.withdraw(amount); } } // Function to display explanation void displayExplanation() { cout << "\n\tConcurrency Control in OpenMP\n"; cout << "\n\tConcurrency:"<<"\n\t\t"<<"Concurrency refers to multiple tasks or processes that can execute in overlapping time periods, potentially simultaneously, in a parallel or multi-threaded environment.\n"; cout << "\n\tConcurrency Control:"<<"\n\t\tIn a multi-threaded environment, when multiple threads or tasks access shared resources, concurrency control mechanisms are employed to manage and synchronize access to these resources.\n"; cout << "\n\tThe program simulates a bank account scenario where withdrawals are attempted concurrently by multiple threads. Each withdrawal operation checks the account balance and updates it if sufficient funds are available. The 'BankAccount' class uses OpenMP locks (omp_lock_t) to synchronize access to the shared account balance. The withdraw() method acquires the lock before updating the balance to ensure that only one thread can modify the balance at a time, preventing data inconsistencies or race conditions.\n"; cout << "\n\tThe makeWithdrawals() function utilizes OpenMP's #pragma omp parallel for directive to parallelize multiple withdrawals, simulating concurrent transactions on the bank account.\n"; cout << "\n\tThis mechanism demonstrates how concurrency control mechanisms, such as locks, help maintain data integrity and prevent race conditions in multi-threaded environments, ensuring consistent and reliable operation when multiple threads access shared resources simultaneously.\n"; // Add more detailed explanation as needed } int main() { int choice; int initialAmount; cout << "\n\t\tConcurrency Control in OpenMP\n"; cout << "\n\tEnter Initial Amount: "; cin >> initialAmount; BankAccount account(initialAmount); do { cout << "\n\tMenu:\n"; cout << "\t1. Simulate withdrawals\n"; cout << "\t2. Explanation\n"; cout << "\t3. Exit\n"; cout << "\tEnter your choice: "; cin >> choice; switch (choice) { case 1: makeWithdrawals(account, 100, 3); makeWithdrawals(account, 25, 3); makeWithdrawals(account, 50, 3); break; case 2: displayExplanation(); break; case 3: cout << "\tExiting...\n"; break; default: cout << "\tInvalid choice. Please enter a valid option.\n"; break; } } while (choice != 3); return 0; }
  • #8: Two phase locking mechanism is restated in the figure, let see it shows two phases Growing Phase Shrinking Phase Now, in the growing phase the process first acquire all the locks during the execution of transaction. After acquiring all the locks, it reaches a point which is known as lock point. Now, in the second phase, it releases all the locks that have applied on the files which is called as shrinking phase. That’s why it named Two-phase locking. (2PL)
  • #9: "Release all locks applied by a transaction only after the transaction has ended." The Shrinking phase does not take place until the transaction has finished running and has either committed or aborted. Two main advantages A transaction always read the value from the committed transaction. All the lock acquisitions and releases can be handled by the system without the transaction aware of that. Now, this policy eliminates the cascaded aborts. Having to undo a committed transaction because it serve a file it should not have seen
  • #10: Now the usual technique apply here such as acquiring all the locks to prevent the hold and wait cycle. Also possible is deadlock detection. In concurrent computing, deadlock is any situation in which no member of some group of entities can proceed because each waits for another member, including itself, to take action, such as sending a message or, more commonly, releasing a lock. Deadlocks are a common problem in multiprocessing systems, parallel computing, and distributed system Blocking, deadlocks, and aborts all result in performance reduction, Now maintaining the explicit graph of which processes has which locks and wants which locks and checking the graph cycles finally it is known in advance the lock will no longer remain in T seconds. So in this case a timeout scheme can be used.
  • #11: Now we have another method of concurrency control, “the optimistic concurrency control” What is OCC? The idea is go ahead and do whatever, without the paying attention to other. If there is a problem, worry about it later. Now this is the optimistic concurrency control.
  • #12: How it keeps track of files which have been read or written. it checks all other transactions to see if any of its files have been changed since the transaction started. If so, the transaction is aborted. If not, it is committed.
  • #13: Now, read the slide in own words.
  • #14: The big advantage of OCC is that, It is deadlock free. And it allows max. parallelism. Because no other processes ever has to wait for a lock. Sometimes it may fail, in which case the transaction has to be run all over again. Under condition of heavy load the probability of failure may go up making OCC a substantially a poor choice. So these are drawbacks of the OCC.
  • #15: #include <iostream> #include <omp.h> using namespace std; //Objective: Simulate bank account withdrawals using multiple threads // concurrently while maintaining data integrity. class BankAccount { private: int balance; omp_lock_t lock; // OpenMP lock for synchronization public: BankAccount(int initialBalance) : balance(initialBalance) { omp_init_lock(&lock); // Initializing the lock } void withdraw(int amount) { omp_set_lock(&lock); // Acquiring the lock /growing phase if (balance >= amount) { balance -= amount; cout << "\tWithdrew Rs." << amount << ". Remaining balance: Rs." << balance << endl; } else { cout << "\n\tInsufficient funds" << endl; } omp_unset_lock(&lock); // Releasing the lock /shrinking phase } ~BankAccount() { omp_destroy_lock(&lock); // Destroying the lock } }; // Function to simulate multiple withdrawals using OpenMP parallel sections void makeWithdrawals(BankAccount& account, int amount, int numWithdrawals) { #pragma omp parallel for for (int i = 0; i < numWithdrawals; ++i) { account.withdraw(amount); } } // Function to display explanation void displayExplanation() { cout << "\n\tConcurrency Control in OpenMP\n"; cout << "\n\tConcurrency:"<<"\n\t\t"<<"Concurrency refers to multiple tasks or processes that can execute in overlapping time periods, potentially simultaneously, in a parallel or multi-threaded environment.\n"; cout << "\n\tConcurrency Control:"<<"\n\t\tIn a multi-threaded environment, when multiple threads or tasks access shared resources, concurrency control mechanisms are employed to manage and synchronize access to these resources.\n"; cout << "\n\tThe program simulates a bank account scenario where withdrawals are attempted concurrently by multiple threads. Each withdrawal operation checks the account balance and updates it if sufficient funds are available. The 'BankAccount' class uses OpenMP locks (omp_lock_t) to synchronize access to the shared account balance. The withdraw() method acquires the lock before updating the balance to ensure that only one thread can modify the balance at a time, preventing data inconsistencies or race conditions.\n"; cout << "\n\tThe makeWithdrawals() function utilizes OpenMP's #pragma omp parallel for directive to parallelize multiple withdrawals, simulating concurrent transactions on the bank account.\n"; cout << "\n\tThis mechanism demonstrates how concurrency control mechanisms, such as locks, help maintain data integrity and prevent race conditions in multi-threaded environments, ensuring consistent and reliable operation when multiple threads access shared resources simultaneously.\n"; // Add more detailed explanation as needed } int main() { int choice; int initialAmount; cout << "\n\t\tConcurrency Control in OpenMP\n"; cout << "\n\tEnter Initial Amount: "; cin >> initialAmount; BankAccount account(initialAmount); do { cout << "\n\tMenu:\n"; cout << "\t1. Simulate withdrawals\n"; cout << "\t2. Explanation\n"; cout << "\t3. Exit\n"; cout << "\tEnter your choice: "; cin >> choice; switch (choice) { case 1: makeWithdrawals(account, 100, 3); makeWithdrawals(account, 25, 3); makeWithdrawals(account, 50, 3); break; case 2: displayExplanation(); break; case 3: cout << "\tExiting...\n"; break; default: cout << "\tInvalid choice. Please enter a valid option.\n"; break; } } while (choice != 3); return 0; }
  • #17: Major goals of concurrency control mechanisms Concurrency control mechanisms firstly need to operate correctly, i.e., to maintain each transaction's integrity rules (as related to concurrency; application-specific integrity rule are out of the scope here) while transactions are running concurrently, and thus the integrity of the entire transactional system. Correctness needs to be achieved with as good performance as possible. In addition, increasingly a need exists to operate effectively while transactions are distributed over processes, computers, and computer networks.