method | advantage | Disadvantage | |
---|---|---|---|
Interrupt mask | Use "on/off interrupt command" to achieve, | Simple and efficient | 1. Not suitable for multi-processor systems 2. Only applicable to kernel process, not applicable to user process |
TesstAndSet instruction (TS instruction, TSL instruction) |
The TSL instruction is implemented by hardware, and it is not allowed to be interrupted during execution, and can only be done in one go
|
Simple to implement No need to check for logic vulnerabilities Suitable for multiprocessors |
Not satisfied with "giving power to wait"
|
swap instruction | Same as above Swap(bool *a,bool *b){ bool temp; temp=*a; *a=*b; *b=temp; }
bool old=true; while(old==true): Swal(&lock,&old) //Critical section code lock=false; //Remaining area code |
Same as above | Same as above |
thought | Disadvantage | |
---|---|---|
Single sign method | After the two processes have finished accessing the critical section, they will hand over the authority to use the critical section to another process. The permission of each process to enter the critical section can only be granted by another process. | Violation: Let in free, Give up and wait |
Double mark first check | Set a boolean array flag[], each element in the array is used to mark the willingness of the process to enter the critical area, and true means that it wants to enter. Before entering the critical section, each process checks whether there are other processes that want to enter the critical section. If not, set its own flag to true, and then start to access the critical section. | Violation: Busy while waiting, Give up and wait |
Double-mark post-inspection | An improved version of the double-mark post-inspection method. The problem with the previous algorithm is to check first and then lock, but these two operations cannot be done in one go, so the two processes may enter the critical section at the same time. So the improvement is to lock first and then check to avoid the above problems. | Violation: Let in free, Limited wait, Give up and wait |
Peterson algorithm | In the double-identification post-checking method, two processes are vying to enter the critical zone, and no one is allowed to enter the critical zone in the end. Peterson's algorithm uses an idea of actively letting the opponent use the critical section first. | Violation: Give up and wait |