Issues related to IPC

来源:互联网 发布:政府办事大厅网络建设 编辑:程序博客网 时间:2024/06/05 17:37

There are briefly three issues related to IPC (InterProcess Communication):

1. How one process can pass information to another.

2. How two or more processes don't get into each other's way when engaging in critical activities (suppose two processes each try to use the same block of memory, reading or writing).

3. How sequencing can be proper when dependencies are present (suppose process A produces data and process B prints it, B has to wait until A has produced some data before starting to print).

 

Generally, the last two issues are much more difficult to deal with. Situations, where two or more processes are reading or writing some shared data and the final result depends on who runs precisely when, are called race conditions. The key point is how to avoid such conditions. Put in other words, what we need is mutual exclusion, which makes sure that if one process is using a shared variable or file, the other processes will be excluded from doing the same thing. The part of the program where the shared memory is accessed is called the critical region (or critical section). Actually, the choice of appropriate primitive operations for achieving mutual exclusion is a major design issue in any operating system. We have to hold four conditions to make a good solution since it should be correct and efficient. The four conditions are:

1. No two processes may be simultaneously inside their critical regions.

2. No assumptions may be made about speeds or the number of CPUs.

3. No process running outside its critical region may block other processes.

4. No process should have to wait forever to enter its critical region.

There are, in my opinion, totally two big kinds of solutions, one is busy waiting, the other is blocking. Busy waiting solutions mainly contain disabling interrupts, lock variables, strict alternation, Peterson's solution, the TSL instruction. The biggist disadvantage is that if one process is in its critical region, all the other ones who want to enter their critical regions have to do some self calculating and testing inside, which waste a lot of CPU time. Sometimes, these solutions of this kind can cause some unexpected effects called priority inversion problem.

However, blocking solutions use some IPC primitives that block instead of wasting CPU time when they are not allowed to enter their critical regions. This kind of solutions contain sleep and wake, semaphores, monitors, and message passing. All of these need much more communications between processes, thun much more complex. We will discuss them later in next achive.

原创粉丝点击