概述
流程图 协作
合作流程 (Cooperating processes)
In the computer system, there are many processes which may be either independent processes or cooperating processes that run in the operating system. A process is said to be independent when it cannot affect or be affected by any other processes that are running the system. It is clear that any process which does not share any data (temporary or persistent) with any another process then the process independent. On the other hand, a cooperating process is one which can affect or affected by any another process that is running on the computer. the cooperating process is one which shares data with another process.
在计算机系统中,有许多进程可以是在操作系统中运行的独立进程或协作进程 。 当一个进程不能影响或不受运行系统的任何其他进程影响时,该进程被称为独立进程。 显然,任何不与任何其他进程共享任何数据(临时或持久性)的进程都与该进程无关。 另一方面,合作进程是可能会影响计算机上运行的任何其他进程或受其影响的进程。 合作过程是与另一过程共享数据的过程。
There are several reasons for providing an environment that allows process cooperation:
提供允许流程合作的环境有几个原因:
Information sharing
信息共享
In the information sharing at the same time, many users may want the same piece of information(for instance, a shared file) and we try to provide that environment in which the users are allowed to concurrent access to these types of resources.
在同时进行信息共享时,许多用户可能需要相同的信息(例如,共享文件),因此我们尝试提供一种允许用户同时访问这些类型的资源的环境。
Computation speedup
计算加速
When we want a task that our process run faster so we break it into a subtask, and each subtask will be executing in parallel with another one. It is noticed that the speedup can be achieved only if the computer has multiple processing elements (such as CPUs or I/O channels).
当我们希望一个任务使我们的进程运行得更快时,我们将其分解为一个子任务,而每个子任务将与另一个任务并行执行。 注意,仅当计算机具有多个处理元素(例如CPU或I / O通道)时,才能实现加速。
Modularity
模块化
In the modularity, we are trying to construct the system in such a modular fashion, in which the system dividing its functions into separate processes.
在模块化方面,我们试图以这种模块化的方式构建系统,其中系统将其功能划分为单独的过程。
Convenience
方便
An individual user may have many tasks to perform at the same time and the user is able to do his work like editing, printing and compiling.
单个用户可能同时执行许多任务,并且该用户能够执行其工作,例如编辑,打印和编译。
A cooperating process is one that can affect or be affected by other process executing in the system cooperating process an:
合作过程是可以影响系统合作过程中执行的其他过程或受其影响的过程:
Directly share a logical address data space (i.e. code & data) - This may result in data inconsistency. It is implemented on threads.
直接共享逻辑地址数据空间(即代码和数据) -这可能导致数据不一致。 它在线程上实现。
Share data only through files/ messages - So we will deal with various to order....orderly execution of cooperating process so that data consistency is maintained.
仅通过文件/消息共享数据 -因此,我们将处理各种按订单处理....有序执行合作过程,以保持数据一致性。
Example- producer-consumer problem
示例-生产者-消费者问题
There is a producer and a consumer, producer produces on the item and places it into buffer whereas consumer consumes that item. For example, a print program produces characters that are consumed by the printer driver. A compiler may produce assembly code, which is consumed by an assembler. The assembler, in turn, may produce objects modules which are consumed by the loader.
有一个生产者和一个消费者,生产者在该项目上生产并将其放入缓冲区,而消费者则消费该项目。 例如,打印程序产生打印机驱动程序消耗的字符。 编译器可能会产生汇编代码,汇编程序会使用这些汇编代码。 汇编程序又可以产生由加载程序消耗的对象模块。
Producer process
生产者过程
while(true)
{
produce an item &
while(counter = = buffer-size);
buffer[int] = next produced;
in = (in+1) % buffer- size;
counter ++;
}
Consumer process
消费过程
While(true)
{
while (counter = = 0);
next consumed = buffer[out];
out= (out+1) % buffer size;
counter--;
}
Here,
这里,
in variable is used by producer t identify the next empty slot in the buffer.
生产者使用变量in标识缓冲区中的下一个空时隙。
out variable is used by the consumer to identify where it has to the consumer the item.
消费者使用out变量来标识物品在消费者那里所处的位置。
counter is used by producer and consumer to identify the number of filled slots in the buffer.
生产者和消费者使用计数器来标识缓冲区中填充的时隙数。
Shared Resources
共享资源
buffer
缓冲
counter
计数器
When producer and consumer are not executed can current then inconsistency arises. Here the value of a counter that is used by both producer and consumer will be wrong if both are executed concurrently without any control. The producer and consumer processes share the following variables:
当生产者和消费者不被执行时,就会产生不一致。 如果生产者和使用者同时使用它们的计数器的值在没有任何控制的情况下并发执行,那么它们的值将是错误的。 生产者和消费者过程共享以下变量:
var n;
type item = .....;
var Buffer : array [0,n-1] of item;
In, out:0..n-1;
With the variables in and out initialized to the value 0. In The shared buffer there are two logical pointers; in and out that is implemented in the form of a circular array. The in variables points to the next free position in the buffer and out variable points to the first full position in the buffer. When, in = out the buffer is empty and when in+1 mod n = out the buffer is full.
变量in和out初始化为值0 。 在共享缓冲区中,有两个逻辑指针: 输入和输出以圆形数组的形式实现。 输入变量指向缓冲区中的下一个空闲位置, 输出变量指向缓冲区中的第一个完整位置。 当in = out时 ,缓冲区为空;当in + 1 mod n = out时 ,缓冲区已满。
翻译自: https://www.includehelp.com/operating-systems/cooperating-processes-in-the-operating-system.aspx
流程图 协作
最后
以上就是现代身影为你收集整理的流程图 协作_操作系统中的协作流程的全部内容,希望文章能够帮你解决流程图 协作_操作系统中的协作流程所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复