ALL > Computer and Education > courses > university courses > graduate courses > modern operating system > zstu 2018-2019-2 class > student homework directory > L20182E060103 >
Homework-3 - A review about mutual exclusion and atomic transactions Version 0
👤 Author: by mahrubachyoutlookcom 2019-03-25 15:18:30
Mutual Exclusion:

A mutual exclusion (mutex) is a program object that prevents simultaneous access to a shared resource. This concept is used in concurrent programming with a critical section, a piece of code in which processes or threads access a shared resource. It is property of concurrency control which is used to prevent race conditions.

Mutual Exclusion Devices:-

  1. Locks

  2. Reader's Writer's Problem

  3. recursive locks

  4. semaphores

  5. monitor

  6. message passing etc.


Requirements:

  1. No more than one thread can be in its critical section at any one time.

  2. A thread which dies in its critical non-critical section will not affect the others' ability to continue.

  3. No deadlock: if a thread wants to enter its critical section then it will eventually be allowed to do so.

  4. No starvation.

  5. Threads are not forced into lock-step execution of their critical sections.


Atomic Operations:

In atomic operations, you can avoid mutual exclusion using atomic operations. When a thread performs an atomic operation, the other threads see it as happening instantaneously. The advantage of atomic operations is that they are relatively quick compared to locks, and do not suffer from deadlock and convoying. The disadvantage is that they only do a limited set of operations, and often these are not enough to synthesize more complicated operations efficiently. But nonetheless you should not pass up an opportunity to use an atomic operation in place of mutual exclusion.

Atomic operations are often used in the kernel, the primary component of most operating systems. However, most computer hardware, compilers and libraries also provide varying levels of atomic operations.

In loading and storing, computer hardware carries out writing and reading to a word-sized memory. To fetch, add or subtract, value augmentation takes place through atomic operations. During an atomic operation, a processor can read and write a location during the same data transmission. In this way, another input/output mechanism or processor cannot perform memory reading or writing tasks until the atomic operation has finished.

Where data is being used by an atomic operation that is also in use by other atomic or non-atomic operations, it can only exist in either sequential processing environments or locking mechanisms have to be used to avoid data errors. Compare and swap is another method but does not guarantee data integrity for atomic operation results.

The problem comes when two operations running in parallel (concurrent operations) utilize the same data and a disparity between the results of the operations occurs. Locking locks variable data and forces sequential operation of atomic processes that utilize the same data or affect it in some way.

Please login to reply. Login

Reversion History

Loading...
No reversions found.