Today I was reading about synchronization. I am a bit confused after reading that the Peterson solution for critical-section problem is a software-based solution. Now my question is: what does it mean "software-based solution" ?
-
Some synchronization methods require hardware support, e.g. atomic instructions, whereas this would appear to be a solution that requires no hardware support, i.e. a software-only solution. – Paul R Aug 05 '12 at 08:07
2 Answers
To solve problem of critical section and enforce mutual exclusion there are several approaches :
First is software based solutions. This solutions have based on algorithms like Peterson algorithm, Dekker's algorithm and Lamport's bakery algorithm ( for more than one process ) to protect the critical section. these solution only assume elementary mutual exclusion at memory access level. Beyond this no support in the hardware, OS or programming language is assumed.
The main problem software approches is their high process overhead and the risk of logical error ( based on OS internals by Stallings )
Beside software solutions, we also have hardware solutions like Interrupt disabling, Compare&Swap instruction and Exchange instruction. These solution employ busy waiting and there's possibility of starvation and deadlock .
Another paradigm to enforce mutual exclusion is to use Semaphores and Monitors which are mechanism implemented by OS and programming languages.
Software-based solution :
1)Sofware-based solution,in the sense that the only characteristic of the hardware they rely on is that if two processes attempt to store a value in the same memory cell, then the hardware will guarantee that the final value will be the same as that written by one of the two, though nothing is guaranteed regarding the order.
2)In software solutions we cannot guarantee that a variable will not be altered between the time that a given process looks at it and the time it itself tries to change it. This is because inspecting a value and altering a value normally require two or more machine instructions, with the possibility of an interrupt (on a uniprocessor) or an access from another processor intervening.This increases the complexity of the solution.
Hardware-based solution:
1)Here special hardware provisions are made such that the operations performed are atomic(as a single operation).
2)Many processors have an instruction which tests and modifies a location in memory in a single, atomic operation, such that no other operation can intervene between the time the location is examined and the time it is modified. For example, Intel IA32 has an XCHG operation that exchanges a register and a memory location.

- 2,334
- 2
- 25
- 29