进程同步相关术语解释

Race Condition: A situation where

1. serveral processes access and manipulate the same data concurrently

2.the outcome of the execution depends on the particular order in which the access takes place

Critical Section: a segment of code

If process p1 is executing in its critical section, then no other processes can be executing in their critical sections

Semaphore: a syncrhonization tool

A semaphore contains an integer variable is accessed only through two standard operations: acquire() and release()

        acquire(){
            while(value <= 0)
                ; //no-op
            value--;
        }    
        release(){
            value++;
        }    
        //上面两个操作都必须是原子操作,并且semaphore上的acquire()和release()不能同时执行

如果value值在运行时只能在0和1之间变化,那Semaphore就起到了
mutex lock的作用:

    
        Semaphore sem = new Semaphore(1);
        sem.acquire();
        ...    //critical section
        sem.release();
        ...    //remainder section

Spinlock (自旋锁): 是一种Semaphore,它能造成一种情形:

一个进程由于等待锁而不停地空转。这个空转的感觉就像在”spin”(自旋)

由于自旋时进程仍处于运行态,所以很浪费CPU.

Deadlock: a situation where

two or more processes are waiting indefinitely for an event that can be caused by one of the waiting processes.

Starvation, or
Infinite Blocking:

1. 一种状况:进程永远获取不到锁

2. 如果锁的等待队列采取LIFO模式,就会靠成这种状况

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.