操作系统关键术语_操作系统的关键部分

操作系统关键术语

比赛条件 (Race condition)

When different process access same data and shared the same resources and their process of the outcome depends on the particular order then this phenomenon is called race condition (i.e. it depends on the speed of exclusion).

当不同的进程访问相同的数据并共享相同的资源,并且其结果的进程取决于特定的顺序时,这种现象称为竞争状态(即,它取决于排除的速度)。

    P()
    {   
        R(i)
        i = i+1;
        w(1)
    }

The race condition is a scenario whereby changing the order of execution of a process we can change the output here the final value is 11 but if a process executes one after another then it will be 12.

竞争条件是一种场景,通过该场景可以更改进程的执行顺序,我们可以在此处更改输出,最终值为11,但是如果一个进程一个接一个地执行,则它将为12。

Solution:

解:

We need to ensure that only process at a time should be manipulating shared data i.e. the processes by synchronized in some way.

我们需要确保一次只能处理共享数据,即以某种方式进行同步。

临界区问题 (Critical section problem)

The portion of the program where the shared data variables or shared resources or shared data will be placed is called a critical section. Each process has a critical section where it changes common variables, update tables, write a table, and so on.

程序中将放置共享数据变量或共享资源或共享数据的部分称为关键部分。 每个进程都有一个关键部分,在其中更改公共变量,更新表,编写表等。

When one process is allowed to execute in its critical section no other process is allowed to execute in its critical section that is no two process be in its critical section at the same time.

当一个进程被允许在其关键部分中执行时,则不允许其他进程在其关键部分中执行,即两个进程不能同时位于其关键部分中。

    P1()
    {  
        while()
        {    
            initial section
            Entry section
            Critical section
            Exit section
            Remainder section
        }
    }

The execution before the critical section is called an initial section and after is called a remainder section. It depends totally on the process whether it will never go into a critical section or will go more than 1 time.

关键部分之前的执行称为初始部分,之后的执行称为其余部分。 它永远不会进入关键部分还是会超过1次完全取决于过程。

Entry section: Each process must repeated process to enter its critical section. Entry section implements this code.

进入部分:每个过程都必须重复过程才能进入其关键部分。 输入部分实现此代码。

Exit section: Code followed by critical section.

退出部分:代码,然后是关键部分。

Remainder section: Remainder code (i.e. other than shared variables/data).

剩余部分:剩余代码(即,共享变量/数据除外)。

    do{
        entry section
        critical section
        exit section
        remainder section
    }  while(true);

Solutions to critical section problem: There are some solutions which satisfy the critical section problem.

临界区问题的解决方案:有些解决方案可以满足临界区问题。

  1. Mutual exclusion

    互斥

    When one process

    当一个过程

    pi is executing in its critical section so at that time no other process can be executing in the critical section problem.

    pi在其关键部分执行,因此在该关键部分问题中没有其他进程可以执行。

  2. Progress

    进展

    When no process is executing in its critical section and there exists some process that wishes to enter in their critical section then only those processes can participate in the decision of which will enter its critical section which is not executing in their remainder section next and this selection cannot be postponed indefinitely.

    当关键部分中没有正在执行的流程,并且有某个进程希望输入其关键部分时,则只有那些进程可以参与决策,哪些进程将进入其关键部分,而该下一步将不在其余部分中执行,并且此选择不能无限期地推迟。

  3. Bounded waiting

    有限的等待

    A bounding function exists on the number of processes and at that time that other processes are allowed to enter their critical section after a process has made a request to enter its critical section and before that request is granted.

    在进程数上存在边界函数,那时,在进程已提出进入其关键部分的请求之后且在该请求被批准之前,允许其他进程进入其关键部分。

Two process solution: 两种Craft.io解决方案:
P0P1
while(1)
{ 
    initial section
    while(turn !=0) 
    Critical section 
    Turn = 1
    Remainder section 
}

P0 P1
while(1)
{ 
    initial section
    while(turn !=0) 
    Critical section 
    Turn = 1
    Remainder section 
}

It is a two process solution which uses a Boolean variables turn. It satisfies mutual exclusion condition but it fails on progress as it required strict alternation the solution is valid.

这是一个使用布尔变量turn的两个过程的解决方案。 它满足互斥条件,但由于需要严格轮换才能有效,因此无法进行。

Example:

例:

P0P1
while(1)
{ 
    initial section
    flag[0] = T
    while(flag[1])
    Critical section;
    Flag[0] = F;
    Remainder section 
}

P0 P1
while(1)
{ 
    initial section
    flag[0] = T
    while(flag[1])
    Critical section;
    Flag[0] = F;
    Remainder section 
}

In this solution, we used a boolean array called flag where each process has one call where false means not interested and true means interested. This solution satisfies mutual exclusion but fails on progress because it suffers from Deadlock.

在此解决方案中,我们使用了一个称为flag的布尔数组,其中每个进程都有一个调用,其中false表示不感兴趣,true表示不感兴趣。 此解决方案可以满足互斥的要求,但是由于出现死锁而无法继续进行。

This is a two process solution known as Peterson solution or Deskerls algorithm.

这是两个过程的解决方案,称为Peterson解决方案或Deskerls算法

Here we have two resources:

这里有两个资源:

  1. Array flag which is used to tell interested or not.

    数组标志,用于告知是否感兴趣。

  2. Turn which is used to decide when both processes are interested.

    Turn用于确定两个流程何时都感兴趣。

It is a valid solution which satisfies both mutual exclusion and progress (bounded wait or well).

这是一个既能满足相互排斥又能满足进展的有效解决方案(无条件等待或成功)。

翻译自: https://www.includehelp.com/operating-systems/critical-section.aspx

操作系统关键术语

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值