JPH04343143A - Shared resource mutual exclusion method for multiprocessor system - Google Patents

Shared resource mutual exclusion method for multiprocessor system

Info

Publication number
JPH04343143A
JPH04343143A JP14395491A JP14395491A JPH04343143A JP H04343143 A JPH04343143 A JP H04343143A JP 14395491 A JP14395491 A JP 14395491A JP 14395491 A JP14395491 A JP 14395491A JP H04343143 A JPH04343143 A JP H04343143A
Authority
JP
Japan
Prior art keywords
mutual exclusion
execution
execute
critical part
semaphore
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
JP14395491A
Other languages
Japanese (ja)
Inventor
Takeshi Sanei
武 三栄
Naohisa Takahashi
直久 高橋
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nippon Telegraph and Telephone Corp
Original Assignee
Nippon Telegraph and Telephone Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nippon Telegraph and Telephone Corp filed Critical Nippon Telegraph and Telephone Corp
Priority to JP14395491A priority Critical patent/JPH04343143A/en
Publication of JPH04343143A publication Critical patent/JPH04343143A/en
Pending legal-status Critical Current

Links

Landscapes

  • Multi Processors (AREA)

Abstract

PURPOSE:To realize the efficient mutual exclusion system of shared resource, in a multiprocessor system in which parallel programs consisting of plural processes are simultneously executed by plural processors. CONSTITUTION:A confusing part 105 within a main storge 3 is the object of mutual exclusion. An inlet operation 106 and an outlet operation 107 are the programs which execute mutual exclusion to the confusing part 105. As mutual exclusion system, both a spin lock type in which a process failed in acquiring the execution right of the confusing part 105 abandons the using right of the processor and is brought into a waiting state and a semaphore type in which the process failed in acquiring the execution right of the confusing part 105 repeats the acquisition of the execution right while securing the utilization right of the processor, are used. The inlet operation 106 changes over the process which is brought into the waiting state for the acquisition of the execution right of the confusing part 105 to the spin lock type or semaphore type corresponding to the execution state of the process currently having the execution right of the confusing part 105.

Description

【発明の詳細な説明】[Detailed description of the invention]

【0001】0001

【産業上の利用分野】本発明は、マルチプロセッサシス
テムにおける共有資源に対する効率的な相互排除方式に
関する。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to an efficient mutual exclusion scheme for shared resources in a multiprocessor system.

【0002】0002

【従来の技術】一般にマルチプロセッサシステムにおけ
る共有資源の相互排除方式はスピンロック方式と2値セ
マフォ方式に分類され、従来、ューザはいずれかを選択
して使用している。以下にスピンロック方式、2値セマ
フォ方式について説明する。
2. Description of the Related Art Mutual exclusion methods for shared resources in multiprocessor systems are generally classified into spinlock methods and binary semaphore methods, and conventionally, users have selected and used either of them. The spinlock method and binary semaphore method will be explained below.

【0003】スピンロック方式   図9はスピンロック方式を用いて相互排除を行うシ
ステムの構成例である。図において、プロセッサ1,2
および主記憶装置3は一つのシステムバス4に接続され
ている。各プロセッサ1,2は、主記憶装置3に格納さ
れた任意のデータの読み出し、書き込み、および、任意
のプログラムの実行が可能である。主記憶装置3には、
鍵901、きわどい部分902、lock操作903、
unlock操作904の各情報が格納される。ここで
、きわどい部分902は、一時には一つのプロセスしか
実行することのできないプログラムであり、相互排除の
対象である。 鍵901の値は1または0であり、きわどい部分902
の実行権を所有するプロセスが存在しているか否かを示
す(ここでは、1は存在、0は空とする)。lock操
作903とunlock操作904は、きわどい部分9
02に対する相互排除を行うプログラムである。
Spinlock Method FIG. 9 shows an example of the configuration of a system that performs mutual exclusion using the spinlock method. In the figure, processors 1 and 2
and main storage device 3 are connected to one system bus 4. Each of the processors 1 and 2 is capable of reading and writing any data stored in the main storage device 3 and executing any program. In the main storage device 3,
key 901, sensitive part 902, lock operation 903,
Each piece of information regarding the unlock operation 904 is stored. Here, the critical portion 902 is a program in which only one process can be executed at a time, and is subject to mutual exclusion. The value of the key 901 is 1 or 0, and the critical part 902
Indicates whether or not a process exists that has execution rights for (here, 1 indicates existence and 0 indicates empty). The lock operation 903 and unlock operation 904 are the critical parts 9
This is a program that performs mutual exclusion for 02.

【0004】図10は、lock操作903とunlo
ck操作904を用いて相互排除を行う操作手順であり
、あるプロセスがきわどい部分902へアクセスする場
合、まずlock操作903によりきわどい部分902
の実行権を得て、きわどい部分902の使用を開始し、
それが終了すると、unlock操作904により実行
権を解除することを示している。これにより、複数のプ
ロセスが同時にlock操作903を実行した場合には
、ただ一つのプロセスがきわどい部分902を実行でき
る。このプロセスがunlock904操作を行うまで
、他のプロセスはきわどい部分902に入れずに空転し
て待つことになる。
FIG. 10 shows a lock operation 903 and an unlo operation.
This is an operation procedure for mutual exclusion using the ck operation 904, and when a certain process accesses the critical part 902, it first accesses the critical part 902 by the lock operation 903.
Obtained execution rights and started using the critical part 902,
When this is completed, the execution right is released by an unlock operation 904. This allows only one process to execute the critical portion 902 if multiple processes execute the lock operation 903 at the same time. Until this process performs the unlock 904 operation, other processes will idle and wait without entering the critical portion 902.

【0005】図11はlock操作の機能ブロック図で
ある。lock操作機能はロック手段1100で構成さ
れる。 ロック手段1100を実行した結果、「きわどい部分」
の実行権を得たプロセスはlock操作を終了し(ロッ
ク成功)、「きわどい部分」の実行権が得られなかった
プロセスは繰り返しロック手段1100の処理を実行す
る(ロック失敗)。
FIG. 11 is a functional block diagram of lock operation. The lock operation function is constituted by a locking means 1100. As a result of executing the locking means 1100, "dangerous part"
The process that has obtained the execution right for the "critical part" ends the lock operation (lock success), and the process that has not obtained the execution right for the "critical part" repeatedly executes the process of the locking means 1100 (lock failure).

【0006】図12はlock操作の処理フロー例で、
破線で囲んだ部分がロック手段1100である。loc
k操作は次の手順で行われる。まず、鍵(図9の901
)を読み出し、この読み出した鍵の値をxとする(ステ
ップ1201)。次に、鍵を1、即ち、他のプロセスが
使用できないように「きわどい部分」をロックする(ス
テップ1202)。ここで、鍵に対する読み出し・書き
込みはtest−and−set命令など、メモリの読
み出しと書き込みが細分化されない基本演算により行わ
れる。つまり、ステップ1201と1202は実際には
1命令で実現される。 次に、ステップ1201で読み出した鍵値xを判定する
(ステップ1203)。そして、x=0(きわどい部分
が未使用)であったからば、該lock操作を終了とし
(ロック成功)、x=1であったならば(きわどい部分
が使用中)、ステップ1201に戻ってlock操作を
繰り返す(ロック失敗)。このロック失敗では、鍵に1
が上書きされるだけである。
FIG. 12 is an example of a processing flow of a lock operation.
The part surrounded by the broken line is the locking means 1100. loc
The k operation is performed in the following steps. First, the key (901 in Figure 9)
) is read out, and the value of the read key is set as x (step 1201). Next, the key is set to 1, that is, the "critical part" is locked so that it cannot be used by other processes (step 1202). Here, reading and writing to the key is performed by basic operations such as a test-and-set instruction in which reading and writing from memory are not subdivided. That is, steps 1201 and 1202 are actually implemented with one instruction. Next, the key value x read out in step 1201 is determined (step 1203). If x=0 (the critical part is unused), the lock operation is terminated (successful locking), and if x=1 (the critical part is in use), the process returns to step 1201 and the lock operation is completed. Repeat operation (lock failure). In this lock failure, the key has 1
is simply overwritten.

【0007】図13はunlock操作の処理を示した
ものである。あるプロセスが「きわどい部分」の実行を
終了すると、unlock操作は鍵に0を書き込む。こ
のunlock操作で鍵に0を書き込むと、lock操
作で空転していたプロセスが0を鍵の値として読み出し
、lock操作を終了して「きわどい部分」に入ること
ができるようになる。
FIG. 13 shows the processing of the unlock operation. When a process finishes executing the "tight part", the unlock operation writes a zero to the key. When this unlock operation writes 0 to the key, the process that was idling due to the lock operation reads 0 as the key value, allowing the lock operation to end and the process to enter the "critical part".

【0008】2値セマフォ方式   図14は2値セマフォ方式を用いて相互排除を行う
システムの構成例である。プロセッサ1,2および主記
憶装置3は一つのシステムバス4に接続されている。各
プロセッサ1,2は主記憶装置3に格納された任意のデ
ータの読み出し、書き込み、および、任意のプログラム
の実行が可能である。主記憶装置3には、きわどい部分
1401、セマフォs1402、セマフォsの待ちプロ
セス行列1403、プロセッサ待ちプロセス行列140
4、P操作1405、V操作1406、プロセス切り替
えプログラム1407が格納される。きわどい部分14
01は、一時には一つのプロセスしか実行することので
きないプログラムであり、相互排除の対象である。セマ
フォs1404は0または1をとり、それぞれきわどい
部分1401の使用中である、あるいは、空いているこ
とを表わす。セマフォsの待ちプロセス行列1403は
、きわどい部分1401の使用が終わるのを待っている
プロセスを整列させたOSの制御データである。プロセ
ッサ待ち行列1404は、プロセッサを割り付けると直
ちに実行可能なプロセスを整列させたOSの制御データ
である。P操作1405とV操作1406はきわどい部
分1401に対する相互排除を行うプログラムである。
Binary Semaphore Method FIG. 14 shows an example of the configuration of a system that performs mutual exclusion using the binary semaphore method. Processors 1 and 2 and main memory 3 are connected to one system bus 4. Each of the processors 1 and 2 is capable of reading and writing arbitrary data stored in the main storage device 3 and executing arbitrary programs. The main storage device 3 includes a critical part 1401, a semaphore s 1402, a waiting process queue 1403 for semaphore s, and a processor waiting process queue 140.
4, P operation 1405, V operation 1406, and process switching program 1407 are stored. Dangerous part 14
01 is a program that can only execute one process at a time, and is subject to mutual exclusion. The semaphore s 1404 takes 0 or 1, indicating that the critical portion 1401 is in use or vacant, respectively. The semaphore s waiting process queue 1403 is OS control data in which processes waiting for the critical portion 1401 to be used are lined up. The processor queue 1404 is OS control data in which processes that can be executed immediately upon allocation of a processor are lined up. The P operation 1405 and the V operation 1406 are programs that mutually exclude the critical portion 1401.

【0009】図15はP操作1405とV操作1406
を用いて相互排除を行う操作手順であり、あるプロセス
がきわどい1401へアクセスする場合、まず、P操作
1405を実行し、きわどい部分1401が空いていれ
ば、きわどい部分1401へアクセスし、それが終了す
るとV操作1406を実行することを示している。これ
により、複数のプロセスが同時にP操作1405を実行
した場合には、ただ一つのプロセスがきわどい部分14
01を実行できる。そして、このプロセスがV操作14
06を行うまで、他のプロセスはセマフォsの待ちプロ
セス行列1405で待たされることになる。
FIG. 15 shows P operation 1405 and V operation 1406.
This is an operation procedure for mutual exclusion using .When a process accesses the critical part 1401, it first executes the P operation 1405, and if the critical part 1401 is vacant, it accesses the critical part 1401, and the process ends. This indicates that V operation 1406 is to be executed. As a result, if multiple processes execute the P operation 1405 at the same time, only one process can perform the critical part 14
01 can be executed. And this process is V operation 14
Until 06 is executed, other processes are made to wait in the waiting process queue 1405 of semaphore s.

【0010】図16は、P操作の機能ブロック図である
。P操作機能は、ロック手段1601とプロセス実行制
御手段1603で構成される。ロック手段1601を実
行した結果、「きわどい部分」の実行権を得たプロセス
はP操作を終了する。「きわどい部分」の実行権を得ら
れなかったプロセスはプロセス実行制御手段1602の
処理に移り、セマフォ待ち状態(ブロック状態)で待機
し、「きわどい部分」の実行権を所有するプロセスのV
操作によってセマフォ待ち状態から解除された場合、「
きわどい部分」の実行権を得てP操作を終了する。
FIG. 16 is a functional block diagram of the P operation. The P operation function is composed of a locking means 1601 and a process execution control means 1603. As a result of executing the locking means 1601, the process that has obtained the right to execute the "critical part" ends the P operation. A process that has not been able to obtain the right to execute the "critical part" moves to the processing of the process execution control means 1602, waits in a semaphore wait state (blocked state), and waits in a semaphore wait state (blocked state),
If you are released from the semaphore wait state by an operation, "
Obtain the right to execute the "dangerous part" and complete the P operation.

【0011】図17はP操作の処理フロー例で、破線で
囲まれた部分が、ロック手段1601およびプロセス実
行制御手段1602の処理である。P操作は、次の手順
で行われる。まず、セマフォs(図14の1402)を
読み出す(ステップ1701)。次に、この読み出した
セマフォsの値を判定し(ステップ1702)、s=1
(きわどい部分が未使用)の場合には、sの値を1減じ
て0(使用中)にして(ステップ1703)、P操作を
終了とする(ロック成功)。ここで、セマフォsに対す
る読み出しと書き込みはプロセスからは細線化されない
基本演算として見えるものである。一方、s=0(きわ
どい部分が使用中)の場合には(ロック失敗)、このP
操作を実行中のプロセスをセマフォ待ちプロセス行列(
図14の1403)の最後尾に加えた後(ステップ17
04)、プロセス切り替えプログラム(図14の140
7)に制御を移し(ステップ1705)、P操作を終了
とする。
FIG. 17 shows an example of the processing flow of the P operation, and the portion surrounded by broken lines is the processing of the locking means 1601 and the process execution control means 1602. The P operation is performed in the following steps. First, semaphore s (1402 in FIG. 14) is read (step 1701). Next, the value of the read semaphore s is determined (step 1702), and s=1
If the critical part is unused, the value of s is reduced by 1 to 0 (in use) (step 1703), and the P operation is terminated (lock success). Here, reading and writing to semaphore s are visible to the process as basic operations that are not thinned. On the other hand, if s = 0 (the critical part is in use) (lock failure), this P
Processes currently performing operations are placed in the semaphore waiting process queue (
1403 in FIG. 14) at the end of (step 17
04), process switching program (140 in FIG.
7) (step 1705), and the P operation is ended.

【0012】図18はV操作の処理フロー例である。あ
るプロセスが「きわどい部分」の使用を終了すると、V
操作では、セマフォ待ちプロセス行列1403が空か調
べ(ステップ1801)、空ならば、セマフォs140
2に1を書き込み(ステップ1802)、V操作を終了
とする。また、セマフォ待ちプロセス行列1403が空
でない場合には、このセマフォ待ち行列から先頭のプロ
セスを取り出し、プロセッサ待ちプロセス行列1404
の先頭に入れ(ステップ1803)、V操作を終了する
。適当な時間経過の後、プロセス切り替えプログラム1
407が実行されると、プロセッサ待ちプロセス行列1
404からプロセスが取り出され、P操作のプロセス実
行制御手段1602の終了時点から処理を再開して、「
きわどい部分」を実行する。
FIG. 18 is an example of the processing flow of V operation. When a process finishes using the "tight part", V
In the operation, it is checked whether the semaphore waiting process queue 1403 is empty (step 1801), and if it is empty, the semaphore s140
2 is written as 1 (step 1802), and the V operation is completed. In addition, if the semaphore waiting process queue 1403 is not empty, the first process is taken out from this semaphore queue, and the processor waiting process queue 1403 is
(step 1803), and the V operation is completed. After an appropriate amount of time has passed, process switching program 1
407 is executed, processor waiting process matrix 1
The process is taken out from 404, and the process is restarted from the point at which the process execution control means 1602 of the P operation ends.
Execute the “dangerous part.”

【0013】[0013]

【発明が解決しようとする課題】スピンロック方式では
、「きわどい部分」が使用中の場合、プロセスが空転し
て鍵の状態を調べ、鍵が0になるまで待っているので、
「きわどい部分」のプログラムに対して、イ.短いプロ
グラムであること、 ロ.入出力など待ち状態になる操作は行わないこと、ハ
.誤りを起こして例外処理プログラムにプロセッサを取
り上げられないこと、 のような制約が課せられる。これらの制約がのため、ス
ピンロック方式は、OSのカーネルなど限られたプログ
ラムの相互排除に用いられるのが一般的であり、通常の
ユーザプログラムには適しいないという欠点があった。
[Problem to be solved by the invention] In the spin lock method, if the "critical part" is in use, the process idles, checks the state of the key, and waits until the key becomes 0.
Regarding the "tight parts" of the program, a. It must be a short program; b. Do not perform operations such as input/output that result in a wait state.c. Restrictions are imposed such that the exception handling program cannot take over the processor due to an error. Because of these restrictions, the spinlock method is generally used for mutual exclusion of limited programs such as the kernel of an OS, and has the disadvantage that it is not suitable for normal user programs.

【0014】ユーザプログラムでスピンロック方式を用
いた場合には、次のような問題が生じる。 (1)バグのため、「きわどい部分」の実行権を長時間
保持する状態を作り出す可能性がある。 (2)lock操作は「きわどい部分」の実行権を所有
するプロセスの状態変化を検出する機能を備えていない
。このため、「きわどい部分」の実行権を所有するプロ
セスが待ち状態に入った場合、あるいは、プロセッサを
取り上げられた場合に、空転を続けるプロセスを実行す
るプロセッサは、そのまま空転を続けて多大に無駄な時
間を費やす。 (3)lock操作の使い方に関する簡単な誤りをおか
すだけで容易にデッドロックに陥ってしまう。しかし、
lock操作は、「きわどい部分」の実行権をどのプロ
セスが所有しているか調べる機能を備えていないので、
簡単なプログラム誤りが原因となる「きわどい部分」の
実行権を決して得ることができないのに待っている状態
を検出し適切や処理を行わせることができない。
[0014] When the spinlock method is used in a user program, the following problem occurs. (1) Due to a bug, it is possible to create a situation where execution rights for "sensitive parts" are held for a long time. (2) The lock operation does not have the function of detecting a change in the state of the process that owns the execution right for the "sensitive part". Therefore, when a process that has the right to execute a "critical part" enters a wait state or when the processor is taken away, the processor that executes the process that continues to idle will continue to idle and waste a lot of time. spend a lot of time. (3) A simple mistake in how to use the lock operation can easily lead to a deadlock. but,
The lock operation does not have the ability to check which process has the execution rights for the "sensitive part", so
It is impossible to detect a waiting state and perform appropriate processing even though the right to execute the "critical part" can never be obtained due to a simple program error.

【0015】2値セマフォ方式では、複数のプロセスが
同一の「きわどい部分」を実行しようとした場合に、P
操作で1を減じられなかったすべてのプロセスについて
次のような操作が行われるため、相互排除においてプロ
セス切り替えが頻繁に生じるという欠点がある。
[0015] In the binary semaphore method, when multiple processes try to execute the same "critical part", P
Since the following operation is performed for all processes that could not be decremented by 1 in the operation, there is a drawback that process switching occurs frequently in mutual exclusion.

【0016】(1)P操作の度にプロセスをセマフォs
の待ちプロセス行列に入れ、プロセス切り替えを行う。 (2)V操作の度にセマフォsの待ちプロセス行列から
プロセッサ割り付け待ちプロセス行列にプロセスを移す
。V操作の後に、プロセス切り替えが発生する。
(1) semaphore the process every time P operation
The process is placed in the waiting process queue and the process is switched. (2) Every time a V operation is performed, a process is moved from the semaphore s waiting process queue to the processor allocation waiting process queue. After the V operation, a process switch occurs.

【0017】上記操作に要する処理量は、スピンロック
方式での相互排除に要する処理量に比べ極めて大きく、
かつ、上記操作は「きわどい部分」の実行権を所有する
プロセスが既に存在する場合には必須であるので、プロ
セスの処理で大きなオーバヘッドとして現われるという
欠点がある。特に、2値セマフォ方式は、処理量の小さ
なプロセスが頻繁に「きわどい部分」を実行するシステ
ムでは、プロセス全体の処理において相互排除のための
オーバーヘッドが占める割合が著しく大きくなるという
欠点がある。また、P操作は、「きわどい部分」の実行
権を所有するプロセスの状態を読み出す機能を備えてい
ないので、該実行権の所有関係により生じるデッドロッ
クなどの誤りを検出し適切な処理が行われないという欠
点がある。
The amount of processing required for the above operation is extremely large compared to the amount of processing required for mutual exclusion in the spinlock method.
Moreover, since the above operation is essential when a process that already has the right to execute the "critical part" exists, it has the disadvantage that it appears as a large overhead in the processing of the process. In particular, the binary semaphore method has the disadvantage that in systems where processes with a small amount of processing frequently execute "critical parts", the overhead for mutual exclusion becomes extremely large in the processing of the entire process. In addition, since the P operation does not have a function to read the state of the process that owns the execution right of the "critical part," errors such as deadlocks that occur due to the ownership relationship of the execution right can be detected and appropriate processing can be performed. There is a drawback that there is no

【0018】相互排除を行うユーザプログラムを実行す
る場合、スピンロック方式と2値セマフォ方式のいずれ
かをユーザは選択して使用する。この時、ユーザはそれ
ぞれの方式の欠点を理解し、かつ、「きわどい部分」を
実行するプロセスの動作を考察した上で決定する必要が
ある。また、ユーザが十分考察して相互排除の方式を選
択した場合でも、スピンロック方式では「きわどい部分
」を実行するプロセスがOSによってプロセッサを取り
上げられるのを防ぐことはできない。そのため「きわど
い部分」の実行権を得るために空転して待つプロセスが
空転しプロセッサを消費し続ける欠点を回避することは
できない。また、2値セマフォ方式では相互排除を頻繁
に行うユーザプログラムの実行において、プロセス切り
替えのオーバーヘッドが大きくなる欠点を回避すること
はできない。
When executing a user program that performs mutual exclusion, the user selects and uses either the spinlock method or the binary semaphore method. At this time, the user needs to understand the shortcomings of each method and consider the operation of the process that executes the "critical part" before making a decision. Furthermore, even if the user carefully considers the mutual exclusion method and selects the mutual exclusion method, the spinlock method cannot prevent a process that executes a "critical part" from having the processor taken over by the OS. Therefore, it is impossible to avoid the drawback that a process that waits idly to obtain the right to execute a "critical part" continues to idle and consume processor power. Furthermore, the binary semaphore method cannot avoid the disadvantage that the overhead of process switching increases when executing user programs that frequently perform mutual exclusion.

【0019】本発明の目的は、ユーザプログラムでの相
互排除にスピンロック方式を用いた場合、「きわどい部
分」を実行するプロセスがプロセッサを取り上げられる
ために、空転して「きわどい部分」の実行権を得るのを
待つプロセスを実行するプロセッサが無駄な空転を費や
す点、および、2値セマフォ方式を用いた場合、頻繁に
相互排除が発生するとプロセス全体の処理においてプロ
セス切り替えに要するオーバーヘッドが占める割合が大
きくなる点、および、両方式の使い分けをユーザが考慮
しなくてはならない点、あるいは、相互排除における誤
り発生を検出して例外処理することができない点を解決
し、ユーザプロセスが頻繁に「きわどい部分」を実行す
るシステムにおいて効率的な共有資源相互排除方式を提
供することにある。
An object of the present invention is that when a spinlock method is used for mutual exclusion in a user program, the process executing the "critical part" is deprived of the processor, so the process idles and loses the right to execute the "critical part". In addition, when using the binary semaphore method, if mutual exclusion occurs frequently, the overhead required for process switching will take up a large proportion of the overall process processing. This solves the problem of large size, the user having to consider whether to use both methods, or the inability to detect errors in mutual exclusion and handle exceptions. The object of the present invention is to provide an efficient shared resource mutual exclusion method in a system that executes "parts".

【0020】[0020]

【課題を解決するための手段】本発明は、異なるプロセ
ッサ上で同時に動作可能な複数プロセスからなる並列プ
ログラムを実行させる機能と、各プロセスが主記憶に置
かれた共有資源へアクセスする機能と、一時にただ一つ
のプロセスしか使用できない部分(きわどい部分と呼ぶ
)の実行を開始する権利(実行権と呼ぶ)を相互に排除
する機能を有するマルチプロセッサシステムにおいて、
以下の機能を有するロック手段、ロック切り替え手段、
プロセス実行状態監視手段及びプロセス実行制御手段を
設ける。
[Means for Solving the Problems] The present invention provides a function for executing a parallel program consisting of a plurality of processes that can operate simultaneously on different processors, a function for each process to access a shared resource located in main memory, In a multiprocessor system that has a function to mutually exclude the right to start execution (called an execution right) of a part that can only be used by one process at a time (called a critical part),
Lock means, lock switching means, having the following functions:
A process execution state monitoring means and a process execution control means are provided.

【0021】ロック手段は、「きわどい部分」の実行権
を持つプロセスが存在しているか否かを示すロック変数
に対して不可分な読み出し・書き込みを行う機能と、「
きわどい部分」の実行権を有するプロセス識別子を記録
する機能を有し、同時に1つ以上のプロセスが「きわど
い部分」の実行権を得ようとした場合に、ただ1つのプ
ロセスだけが「きわどい部分」の実行権を得ることを保
証し、「きわどい部分」の実行権を得たプロセスの識別
子を記録する。
[0021] The locking means has a function of reading and writing inseparably from a lock variable indicating whether or not there is a process that has the right to execute the "critical part";
It has a function to record the process identifier that has the right to execute the "sensitive part", and if one or more processes try to obtain the execution right to the "sensitive part" at the same time, only one process will be able to execute the "sensitive part". The identifier of the process that gained execution rights for the "sensitive part" is recorded.

【0022】ロック切り替え手段は、現在の相互排除の
方式がスピンロック方式が2値セマフォ方式かを調べる
機能と、相互排除を行うプロセスのプログラムの誤りを
検出する機能を有し、現在の相互排除の方式によって「
きわどい部分」の実行権を得るために待つプロセスの待
機方法を変化させ、あるいは、誤りを起こしたプロセス
に例外処理を行わせる。
The lock switching means has a function of checking whether the current mutual exclusion method is a spin lock method or a binary semaphore method, and a function of detecting an error in the program of the process that performs mutual exclusion. By the method of “
Change the waiting method of a process that waits to obtain the right to execute a "critical part," or have the process that caused the error perform exception handling.

【0023】プロセス実行状態監視手段は、OSの制御
データであるプロセス制御ブロック(PCBと呼ぶ)を
プロセスのアドレス空間内にマッピングする機能と、マ
ッピングしたPCBのプロセス状態フィールドを読み出
す機能と、現在の相互排除の方式をスピンロック方式か
2値セマフォ方式かに変化させる機能を有し、「きわど
い部分」の実行権を得るために待つプロセスに「きわど
い部分」の実行権を有するプロセスの実行状態を監視さ
せ、その結果に従って待機方法を変化させる。
The process execution state monitoring means has a function of mapping a process control block (called a PCB), which is control data of the OS, into the process address space, a function of reading the process state field of the mapped PCB, and a function of reading the process state field of the mapped PCB. It has a function that changes the mutual exclusion method to the spin lock method or the binary semaphore method, and allows the process waiting to obtain the execution right for the "critical part" to check the execution state of the process that has the execution right for the "critical part". Monitor the system and change the waiting method according to the results.

【0024】プロセス実行制御手段は、「きわどい部分
」の実行権を得るために待つプロセスをプロセッサ待ち
状態にすると、セマフォ待ち状態にする機能と、プロセ
ス切り替えプログラムを実行する機能を有し、プロセス
状態監視手段の結果により、「きわどい部分」の実行権
を得るために待つプロセスの実行状態をプロセッサ待ち
状態、あるいは、セマフォ待ち状態に変化させる。
The process execution control means has a function of placing a process waiting to obtain the right to execute a "critical part" into a processor wait state, and a function of placing the process in a semaphore wait state and a function of executing a process switching program, and changing the process state. Depending on the result of the monitoring means, the execution state of the process waiting to obtain the right to execute the "critical part" is changed to a processor wait state or a semaphore wait state.

【0025】[0025]

【作用】本発明では、「きわどい部分」の実行権を有す
るプロセスの実行状態に従って、相互排除の方式をスピ
ンロック方式あるいは2値セマフォ方式に選択的に変化
して、「きわどい部分」の実行権を得るのを待つプロセ
スの実行を制御する。また、相互排除を行うプロセスの
プログラムの誤りを検出して例外処理を行わせる。これ
により、ユーザプロセスなどが頻繁に「きわどい部分」
をアクセスするような場合、相互排除を効率的に行うこ
とができるようになる。
[Operation] In the present invention, the mutual exclusion method is selectively changed to the spin lock method or the binary semaphore method according to the execution state of the process that has the execution right of the "critical part", and the execution right of the "critical part" is changed. Control the execution of a process that waits for a . Additionally, an error in the program of a process that performs mutual exclusion is detected and exception handling is performed. As a result, user processes, etc. are frequently
, mutual exclusion can be performed efficiently.

【0026】[0026]

【実施例】図1は本発明の一実施例のシステム構成図で
ある。図において、プロセッサ1,2および主記憶装置
3は一つのシステムバス4に接続されている。各プロセ
ッサ1,2は、主記憶装置3に格納された任意のデータ
の読み出し、書き込み、および任意のプログラムの実行
が可能である。主記憶装置3には、プロセス制御ブロッ
ク101、プロセッサ待ちプロセス行列102、セマフ
ォ待ちプロセス行列103、鍵104、きわどい部分1
05、入口操作106、出口操作107、例外処理プロ
グラム108、プロセス切り替えプログラム109が格
納されている。
DESCRIPTION OF THE PREFERRED EMBODIMENTS FIG. 1 is a system configuration diagram of an embodiment of the present invention. In the figure, processors 1 and 2 and main memory 3 are connected to one system bus 4. Each of the processors 1 and 2 is capable of reading and writing arbitrary data stored in the main storage device 3 and executing arbitrary programs. The main storage device 3 includes a process control block 101, a process queue 102 waiting for a processor, a process queue 103 waiting for a semaphore, a key 104, and a critical part 1.
05, an entrance operation 106, an exit operation 107, an exception handling program 108, and a process switching program 109 are stored.

【0027】プロセス制御ブロック(以下、PCBと呼
ぶ)101は、OSによりプロセスごとに作られる制御
データであり、プロセスの実行状態やプロセスへの資源
の割り付け状況などが書き込まれ、ユーザプロセスから
は直接書き込み・読み出しができないよう保護されてい
る。PCB内にはプロセスの状態フィールドがあり、プ
ロセスが実行である、あるいは、プロセッサ待ち状態で
ある、あるいは、イベント待ちなどのブロック状態であ
ることを示す。図1では、一例としてプロセスA、Bの
PCBを示し、プロセスA、Bはそれぞれプロセッサ1
,2に割り付けられて実行中であることを示している。
The process control block (hereinafter referred to as PCB) 101 is control data created for each process by the OS, in which the execution status of the process, the allocation status of resources to the process, etc. are written, and it is not directly accessible from the user process. It is protected against writing and reading. There is a process status field in the PCB, which indicates whether the process is running, waiting for a processor, or blocking, such as waiting for an event. In FIG. 1, PCBs of processes A and B are shown as an example, and processes A and B are each processor 1.
, 2 and is being executed.

【0028】プロセッサ待ちプロセス行列102は、プ
ロセッサを割り付けると直ちに実行可能なプロセスのP
CBを整列させたOSの制御データである。セマフォ待
ちプロセス行列103は、きわどい部分105の使用が
終わるのを待っているプロセスを整列させたOSの制御
データである。
The processor waiting process matrix 102 stores P of processes that can be executed immediately after a processor is allocated.
This is OS control data in which CBs are arranged. The semaphore waiting process queue 103 is OS control data in which processes waiting for the critical portion 105 to be used are lined up.

【0029】鍵104は、PCBアドレスとロック変数
とロック型変数からなる。PCBアドレスには、きわど
い部分105の実行権を所有しているプロセスのPCB
の先頭アドレス、または、0が格納されている。ロック
変数は、きわどい部分105の実行権を所有するプロセ
スが存在するか否かを示す(1は存在、0は存在しない
とする)。ロック型変数は現在の相互排除方式がスピン
ロック方式かセマフォ方式かを示す。
The key 104 consists of a PCB address, a lock variable, and a lock type variable. The PCB address contains the PCB of the process that owns the execution right for the sensitive part 105.
The first address or 0 is stored. The lock variable indicates whether there is a process that owns the execution right for the sensitive part 105 (1 means it exists, 0 means it does not exist). The lock type variable indicates whether the current mutual exclusion method is a spinlock method or a semaphore method.

【0030】きわどい部分105は、一時には一つのプ
ロセスしか実行することのできないプログラムであり、
相互排除の対象である。入口操作106と出口操作10
7は、きわどい部分105に対する相互排除を行なうプ
ログラムである。例外処理プログラム108は、相互排
除に関する誤りを処理するプログラムであり、プロセス
切り替えプログラム109はプロセッサ1,2をプロセ
スに割り付けるプログラムである。
[0030] The critical part 105 is a program that can only execute one process at a time.
Subject to mutual exclusion. Entry operation 106 and exit operation 10
7 is a program that performs mutual exclusion for the critical portion 105. The exception handling program 108 is a program that processes errors related to mutual exclusion, and the process switching program 109 is a program that allocates processors 1 and 2 to processes.

【0031】図2は入口操作106と出口操作107を
用いて、プロセスがきわどい部分105の相互排除を行
う操作手順を示したものである。即ち、あるプロセスが
「きわどい部分」をアクセスする場合、まず、入口操作
を実行し、「きわどい部分」が他のプロセスで使用中で
なければ、「きわどい部分」の実行権を得て「きわどい
部分」へアクセスし、それが終了すると、出口操作を実
行する。これにより、複数のプロセスが同時に入口操作
を実行した場合には、ただ一つのプロセスが「きわどい
部分」を実行できる。そして、このプロセスが出口操作
を行なうまで他のプロセスは「きわどい部分」に入るこ
とができない。
FIG. 2 illustrates an operating procedure for mutual exclusion of process critical portions 105 using inlet operation 106 and outlet operation 107. In other words, when a process accesses a "sensitive part", it first performs an entry operation, and if the "sensitive part" is not in use by another process, it gains execution rights to the "sensitive part" and accesses the "sensitive part". ” and when it finishes, performs the exit operation. This allows only one process to perform the "critical part" if multiple processes perform entry operations at the same time. No other process can enter the "critical part" until this process performs the exit operation.

【0032】図3は、入口操作の機能ブロック図である
。入口操作機能はロック手段301、ロック切り替え手
段302、プロセス実行状態監視手段303およびプロ
セス実行制御手段304で構成される。図3に示すよう
に、入口操作では、図11のスピンロック方式、図15
の2値セマフォ方式と比べ、ロック切り替え手段302
およびプロセス実行状態監視手段303が付加される。 また、後述するように、ロック手段301およびプロセ
ス実行制御手段304も機能拡張されている。
FIG. 3 is a functional block diagram of the entrance operation. The entrance operation function is comprised of a locking means 301, a lock switching means 302, a process execution state monitoring means 303, and a process execution control means 304. As shown in Fig. 3, in the entrance operation, the spin lock method in Fig. 11,
Compared to the binary semaphore method, the lock switching means 302
and process execution state monitoring means 303 are added. Furthermore, as will be described later, the locking means 301 and the process execution control means 304 are also functionally expanded.

【0033】次に、図4から図7を用いて入口操作の各
手段での処理を詳述するが、図1に示すように、鍵10
5のPCBアドレスとロック変数の初期値を0とし、ロ
ック型変数の初期値をスピンロック方式とし、入口操作
を実行するプロセスはプロセスAとする。
Next, the processing of each means of entrance operation will be explained in detail using FIGS. 4 to 7. As shown in FIG.
It is assumed that the initial values of the PCB address and the lock variable of No. 5 are 0, the initial value of the lock type variable is the spin lock type, and the process that executes the entry operation is process A.

【0034】図4は、ロック手段301の処理フロー例
である。太線で囲った部分が、従来のスピンロック方式
および2値セマフォ方式に対して、本発明で新たに付加
した操作手順である。 (1)プロセスAは鍵のPCBアドレスを読み出す(ス
テップ401)。読み出した値をaとする。次に、この
aの値を判定する(ステップ402)。aが0(初期値
)の場合には、「きわどい部分」の実行権を所有するプ
ロセスが存在しない可能性があるため、(2)に行く。 その他の場合には、「きわどい部分」の実行権を所有す
るプロセスが存在することを意味するので、処理はロッ
ク切り替え手段302へ移る。 (2)aが0の場合、鍵のロック変数を読み出す(ステ
ップ403)。読み出した値をxとする。次に鍵のロッ
ク変数を1にする(ステップ404)。ここで、ロック
変数に対する読み出し・書き込みはtest−and−
set命令などによって不可分演算によりなされるもの
である。次に、読み出したロック変数の値xを判定する
(ステップ405)。xが0の場合には、プロセスAが
「きわどい部分」の実行権を得たことを意味するので、
(3)へ行く。xが0でない場合には、(1)に行く。 これらの操作はスピンロック方式および2値セマフォ方
式での手順と同一である。 (3)読み出した鍵のロック変数の値xが0の場合、プ
ロセスA(自プロセス)のPCBの先頭アドレスを鍵の
PCBアドレスに書き込み、入口操作を終了する(ステ
ップ406)。
FIG. 4 is an example of the processing flow of the locking means 301. The part surrounded by thick lines is the operation procedure newly added in the present invention to the conventional spin lock method and binary semaphore method. (1) Process A reads the PCB address of the key (step 401). Let the read value be a. Next, the value of a is determined (step 402). If a is 0 (initial value), there is a possibility that there is no process that has the right to execute the "critical part", so go to (2). In other cases, it means that there is a process that owns the execution right for the "critical part", so the processing moves to the lock switching means 302. (2) If a is 0, read the lock variable of the key (step 403). Let the read value be x. Next, the lock variable of the key is set to 1 (step 404). Here, reading and writing to the lock variable is done by test-and-
This is performed by an atomic operation using a set instruction or the like. Next, the value x of the read lock variable is determined (step 405). If x is 0, it means that process A has obtained the right to execute the "critical part", so
Go to (3). If x is not 0, go to (1). These operations are the same as those in the spinlock method and binary semaphore method. (3) If the value x of the read lock variable of the key is 0, the start address of the PCB of process A (self-process) is written to the PCB address of the key, and the entry operation is completed (step 406).

【0035】図5は、ロック切り替え手段302の処理
フロー例である。ロック切り替え手段302は、従来の
スピンロック方式および2値セマフォ方式にはない手段
であり、本発明により付加されたものである。ロック切
り替え手段302の入口は、図4のステップ402(n
0側)から制御が移された場合、すなわち、プロセスA
がロック手段301において「きわどい部分」の実行権
を得られなかった場合である。 (1)ロック手段301において読み出した鍵のPCB
アドレスの値aがプロセスA(自プロセス)のPCBの
先頭アドレスか否か判定する(ステップ501)。先頭
アドレスの場合、プロセスAのプログラムに誤りがあり
、「きわどい部分」の実行権を新たに得ることができな
いことを意味するので、例外処理を行うために、後述の
プロセス実行制御手段304の処理へ移る。その他の場
合には、次の(2)へ行く。 (2)鍵のロック型変数の値を読み出す(ステップ50
2)。読み出した値をcとする。次にこのロック型変数
の値cを判定する(ステップ503)。そして、現在の
相互排除の方式が2値セマフォ方式であることをcが示
している場合、プロセスAは、セマフォ待ちプロセスの
状態で、「きわどい部分」の実行権が解放されるのを待
つことを意味するので、プロセス実行制御手段304へ
行く。それ以外の場合には、プロセス実行状態監視手段
303へ行く。
FIG. 5 shows an example of the processing flow of the lock switching means 302. The lock switching means 302 is a means not found in the conventional spin lock method and binary semaphore method, and is added according to the present invention. The entrance of the lock switching means 302 is step 402 (n
0 side), that is, process A
This is a case where the locking means 301 cannot obtain the right to execute the "critical part". (1) PCB of the key read out by the locking means 301
It is determined whether the address value a is the start address of the PCB of process A (self-process) (step 501). In the case of the first address, it means that there is an error in the program of process A and that the right to execute the "critical part" cannot be newly obtained. Therefore, in order to handle the exception, the processing of the process execution control means 304, which will be described later, is performed. Move to. In other cases, go to the next step (2). (2) Read the value of the lock type variable of the key (step 50
2). Let the read value be c. Next, the value c of this lock type variable is determined (step 503). If c indicates that the current mutual exclusion method is the binary semaphore method, process A waits for the execution right of the "critical part" to be released in the state of a semaphore waiting process. , so it goes to the process execution control means 304. In other cases, the process goes to the process execution state monitoring means 303.

【0036】図6は、プロセス実行状態監視手段303
の処理フロー例である。プロセス実行状態監視手段30
3も従来のスピンロック方式および2値セマフォ方式に
はない手段であり、本発明により付加されるものである
。プロセス実行状態監視手段303の入口は、図5のス
テップ503(no側)から制御が移された場合、すな
わち、プロセスAが「きわどい部分」の実行権を得られ
ず、かつ、相互排除の方式がスピンロック方式の場合で
ある。 (1)ロック手段301で読み出した鍵のPCBアドレ
スの値aを先頭アドレスとするPCBがプロセスA(自
プロセス)のアドレス空間内にマッピングされているか
判定し(ステップ601)、既に、マッピングしてある
場合には(2)へ行く。マッピングしていない場合には
、aを先頭アドレスとするPCBを、プロセスAのアド
レス空間内にマッピングした後(ステップ602)、(
2)へ行く。ここでマッピングとは、アクセス可能なフ
ァイルをプロセスのアドレス空間の一部として使用する
ことであり、UNIXのmmapなど汎用OSのマッピ
ング機能を用いることにより実現される。UNIXの場
合、PCBを含むカーネルのデータ領域がファイルの形
で提供されているため、これをマッピングすることによ
り、PCBへのアクセスが可能となる。 (2)プロセスAのアドレス空間内にマッピングされた
値aを先頭アドレスとするPCBからプロセスの状態フ
ィールドを読み出す(ステップ603)。読み出した値
をsとする。次に、このsの状態を判定する(ステップ
604、605)。「きわどい部分」の実行権を有する
プロセスが実行中であることをsの値が示している場合
には(ステップ604のyes側)、プロセス実行制御
手段304の処理へ行く。「きわどい部分」の実行権を
有するプロセスが実行中でなく、プロセッサ待ちプロセ
ス行列に入っていることをsの値が示している場合には
(ステップ605のyes側)、やはりプロセス実行制
御手段304の処理へ行く。それ以外の場合、即ち、「
きわどい部分」の実行権を有するプロセスがイベント待
ちなど、ブロック状態であることをsの値が示している
場合には(ステップ605のno側)、鍵のロック型変
数をセマフォ方式にした後(ステップ606)、プロセ
ス実行制御手段304の処理へ行く。
FIG. 6 shows the process execution status monitoring means 303
This is an example of the processing flow. Process execution state monitoring means 30
3 is also a means not found in the conventional spin lock method and binary semaphore method, and is added by the present invention. The process execution state monitoring means 303 enters when control is transferred from step 503 (no side) in FIG. is the case of the spinlock method. (1) Determine whether the PCB whose start address is the value a of the PCB address of the key read by the locking means 301 is mapped in the address space of process A (self-process) (step 601), and check if the PCB has already been mapped. If so, go to (2). If not mapped, after mapping the PCB whose first address is a into the address space of process A (step 602),
Go to 2). Mapping here means using an accessible file as part of the address space of a process, and is achieved by using a mapping function of a general-purpose OS such as mmap of UNIX. In the case of UNIX, since the kernel data area including the PCB is provided in the form of a file, the PCB can be accessed by mapping this. (2) Read the process status field from the PCB whose starting address is the value a mapped in the address space of process A (step 603). Let the read value be s. Next, the state of this s is determined (steps 604, 605). If the value of s indicates that the process having the right to execute the "critical part" is being executed (YES in step 604), the process goes to the process execution control means 304. If the value of s indicates that the process that has the right to execute the "critical part" is not being executed but is in the processor waiting process queue (YES in step 605), the process execution control means 304 Go to processing. Otherwise, i.e. “
If the value of s indicates that the process that has the execution right for the "critical part" is in a blocked state, such as waiting for an event (no in step 605), after setting the lock type variable of the key to the semaphore method ( Step 606), the process goes to the process execution control means 304.

【0037】図7はプロセス実行制御手段304の処理
フロー例である。プロセス実行制御手段304の入口は
、ロック切り替え手段302において、相互排除におけ
る誤りを検出した場合(図5のステップ501のyes
側)、相互排除の方式が2値セマフォ方式を検出した場
合(図5のステップ503のyes側)、及び、プロセ
ス実行状態監視手段303において、「きわどい部分」
の実行権を有するプロセスがブロック状態であることを
検出してロック変数をスピンロック方式から2値セマフ
ォ方式に変更した場合(図6のステップ606)、「き
わどい部分」の実行権を有するプロセスがプロセッサ待
ち状態であることを検出した場合(図6のステップ60
5のyes側)、「きわどい部分」の実行権を有するプ
ロセスが実行中であることを検出した場合(図6のステ
ップ604のyes側)の計5つである。図7において
、太線で囲った部分が、従来の2値セマフォ方式に対し
て、本発明で新たに付加した操作である。 (1)図5のステップ501(yes側)から制御が移
された場合、すなわち、ロック切り替え手段302にお
いて、相互排除における誤りを検出した場合には、例外
処理プログラムに制御を移し(ステップ701)、入口
操作を終了する。 (2)図5のステップ503(yes側)から制御が移
された場合、すなわち、ロック切り替え手段302にお
いて、相互排除の方式が2値セマフォ方式であった場合
、および、図6のステップ606から制御を移された場
合、すなわち、プロセス実行状態監視手段303におい
て、「きわどい部分」の実行権を有するプロセスがブロ
ック状態であることを検出してセマフォ方式に変更した
場合には、従来の2値セマフォ方式と同様の待機方法で
、「きわどい部分」の実行権が解放されるのを待つため
に、汎用OSが持つ2値セマフォの機能を用いて、プロ
セスA(自プロセス)のPCBをセマフォ待ちプロセス
行列の最後尾に加える(ステップ702)。そして、(
4)へ行く。 (3)図6のステップ605(yes側)から制御が移
された場合、すなわち、プロセス実行状態監視手段30
3において、「きわどい部分」の実行権を有するプロセ
スがプロセッサ待ち状態であることを検出した場合には
、「きわどい部分」の実行権を有するプロセスがプロセ
ッサを取り上げられて、停止しており、「きわどい部分
」の実行権を得るために待つプロセスに割り付けられた
プロセッサは無駄な時間を費やすことを意味するので、
自プロセスに割り付けられたプロセッサを解放するため
に、汎用OSのプロセス制御機能を使用して、プロセッ
サ待ちプロセス行列の最後尾にプロセスAのPCBを入
れ(ステップ703)、(4)へ行く。 (4)プロセス切り替えプログラムを実行し、自プロセ
スに割り付けられたプロセッサを他のプロセスに渡す(
ステップ704)。しばらく後に、再び、このプロセス
(プロセスA)にプロセッサが割り付けられた時には、
入口操作を行うために、再びロック手段301へ行く(
図4のステップ401へ制御を移す)。この操作は、従
来の2値セマフォ方式と同一の操作である。 (5)図6のステップ604(yes側)から制御を移
された場合、すなわち、プロセス実行状態監視手段30
3において、「きわどい部分」の実行権を有するプロセ
スが実行中であることを検出した場合には、「きわどい
部分」の実行権が比較的短時間のうちに解放される可能
性があるため、「きわどい部分」の実行権を獲得するた
めに、再びロック手段301へ行く(図4のステップ4
01へ制御を移す)。
FIG. 7 is an example of a processing flow of the process execution control means 304. The entrance to the process execution control means 304 is activated when the lock switching means 302 detects an error in mutual exclusion (yes in step 501 of FIG.
side), when the mutual exclusion method detects the binary semaphore method (yes side of step 503 in FIG. 5), and in the process execution state monitoring means 303, "critical part"
When it is detected that the process with the execution right for the "critical part" is in a blocked state and the lock variable is changed from the spin lock method to the binary semaphore method (step 606 in FIG. 6), the process that has the execution right for the "critical part" If it is detected that the processor is in a waiting state (step 60 in FIG.
5), and when it is detected that a process that has the right to execute the "critical part" is being executed (step 604 in FIG. 6, yes). In FIG. 7, the part surrounded by thick lines is the operation newly added in the present invention to the conventional binary semaphore method. (1) When control is transferred from step 501 (yes side) in FIG. 5, that is, when the lock switching means 302 detects an error in mutual exclusion, control is transferred to the exception handling program (step 701). , exit the entry operation. (2) When control is transferred from step 503 (yes side) in FIG. 5, that is, when the mutual exclusion method is a binary semaphore method in the lock switching means 302, and when control is transferred from step 606 in FIG. When control is transferred, that is, when the process execution status monitoring unit 303 detects that the process that has the execution right for the "critical part" is in a blocked state and changes to the semaphore method, the conventional binary Using a waiting method similar to the semaphore method, in order to wait for the execution right of the "critical part" to be released, the binary semaphore function of a general-purpose OS is used to put the PCB of process A (its own process) into a semaphore state. It is added to the end of the process matrix (step 702). and,(
Go to 4). (3) When control is transferred from step 605 (yes side) in FIG. 6, that is, the process execution state monitoring means 30
In step 3, if it is detected that the process that has the right to execute the "critical part" is waiting for the processor, the process that has the right to execute the "critical part" has been deprived of the processor and has stopped. This means that a processor allocated to a process that waits to get the right to execute a "critical part" is wasted time.
In order to release the processor allocated to the own process, the process control function of the general-purpose OS is used to place the PCB of process A at the end of the process queue waiting for the processor (step 703), and the process goes to (4). (4) Execute the process switching program and pass the processor assigned to the own process to another process (
Step 704). After a while, when a processor is assigned to this process (process A) again,
To perform the entrance operation, go to the locking means 301 again (
Control is transferred to step 401 in FIG. 4). This operation is the same as the conventional binary semaphore method. (5) When control is transferred from step 604 (yes side) in FIG. 6, that is, the process execution state monitoring means 30
In step 3, if it is detected that a process that has the right to execute the "sensitive part" is running, the right to execute the "sensitive part" may be released within a relatively short period of time. In order to acquire the execution right for the "critical part", go to the locking means 301 again (step 4 in FIG. 4).
01).

【0038】図8は出口操作の処理フロー例である。太
線が囲った部分が従来のスピンロック方および2値セマ
フォ方式に対して本発明で新たに付加した操作である。 (1)鍵のロック型変数を読み出す(ステップ801)
。読み出した値をcとする。鍵のロック型変数をビジー
ウエイト方式にし(ステップ802)、鍵のPCBアド
レスを0にする(ステップ803)。次に、読み出した
鍵のロック型変数の値cを判定し(ステップ804)、
cの値がビジーウエイ方式の場合には(2)へ行く。c
の値がセマフォ方式を示している場合には、汎用OSが
持つ2値セマフォの機能を用いて以下の動作を行う。セ
マフォ待ちプロセス行列が空であるか調べ(ステップ8
05)、空ならば(2)へ行く。空でないならばセマフ
ォ方式待ち行列内の全プロセスを取り出し、プロセッサ
待ちプロセス行列に入れ(ステップ806)、(2)へ
行く。 (2)鍵のロック変数を0にし、出口操作を終了する。
FIG. 8 is an example of the processing flow of the exit operation. The part surrounded by thick lines is the operation newly added in the present invention to the conventional spin lock method and binary semaphore method. (1) Read the lock type variable of the key (step 801)
. Let the read value be c. The lock type variable of the key is set to the busy-wait method (step 802), and the PCB address of the key is set to 0 (step 803). Next, the value c of the lock type variable of the read key is determined (step 804),
If the value of c is the busy way method, go to (2). c.
If the value indicates the semaphore method, the following operations are performed using the binary semaphore function of the general-purpose OS. Check whether the semaphore waiting process queue is empty (step 8)
05), if empty, go to (2). If it is not empty, all processes in the semaphore queue are taken out and placed in the processor waiting process queue (step 806), and the process goes to (2). (2) Set the key lock variable to 0 and complete the exit operation.

【0039】[0039]

【発明の効果】本発明では、「きわどい部分」の実行権
を所有するプロセスがプロセッサを取り上げられたこと
を検出し、「きわどい部分」の実行権を得るために空転
して待つプロセスからもプロセッサを取り上げることに
より、無駄な空転によるプロセッサの浪費を抑えること
が可能となり、あるいは、「きわどい部分」の実行権を
有するプロセス実行状態に従って、相互排除の方式をス
ピンロック方式か2値セマフォ方式かを切り替えること
により、「きわどい部分」の実行権を得るために待つプ
ロセスがセマフォ待ちプロセスの状態になる回数を減少
させ、プロセス切り替えの発生回数を減少させ、プロセ
ス切り換えのオーバーヘッドを小さく抑えることが可能
となり、または、ユーザが相互排除の方式を選択する必
要がなくなり、あるいは、相互排除における誤り発生を
検出することにより例外処理を行うことが可能となり、
ユーザプロセスが頻繁に「きわどい部分」を実行するシ
ステムにおいて効率的な相互排除方式を提供することが
できるという利点がある。
[Effects of the Invention] The present invention detects that the processor is taken away from a process that has the right to execute the "critical part," and prevents the process from idling and waiting to get the right to execute the "critical part" to take over the processor. By addressing this, it is possible to reduce the waste of processor power due to unnecessary idle operations, or to select whether the mutual exclusion method is a spin lock method or a binary semaphore method, depending on the execution state of the process that has the execution right for the "critical part". By switching, it is possible to reduce the number of times that a process waiting to obtain execution rights for a "critical part" becomes a semaphore waiting process, reduce the number of times that process switching occurs, and keep the overhead of process switching small. Or, the user does not need to select a mutual exclusion method, or it becomes possible to perform exception handling by detecting the occurrence of an error in mutual exclusion,
An advantage is that it can provide an efficient mutual exclusion scheme in systems where user processes frequently perform "tight parts".

【0040】さらに、「きわどい部分」の実行権を得る
ために待つプロセスが、「きわどい部分」の実行権を所
有するプロセスのプロセス制御ブロック(PCB)を、
自アドレス空間内にマッピングしてから、その実行状態
を調べることにより、高速に値を読み出すことができる
という利点がある。
[0040]Furthermore, a process waiting to obtain the right to execute the "critical part" may access the process control block (PCB) of the process that owns the right to execute the "critical part".
By mapping into the own address space and then checking its execution status, there is an advantage that the value can be read out at high speed.

【0041】さらに、「きわどい部分」の実行権を所有
するプロセスが実行状態にあるとき、他のプロセスが空
転して待つ操作手順の中にメモリへの書き込み命令が存
在しないという利点がある。キヤッシュを備えたメモリ
共有型マルチプロセッサの場合には、このことは、キヤ
ッシュメモリ内のデータを参照するだけであり、主記憶
装置へのアクセスあるいは他のプロセッサのキヤッシュ
へのデータ転送が生じないことを意味し、空転のために
他のプロセッサの性能を劣化させないという利点がある
Furthermore, when the process that has the right to execute the "critical part" is in the execution state, there is an advantage that there is no write instruction to the memory in the operation procedure in which other processes idle and wait. In the case of a shared memory multiprocessor with a cache, this means only referencing data in the cache memory and no access to main memory or data transfer to other processors' caches. This means that the performance of other processors is not degraded due to idling.

【図面の簡単な説明】[Brief explanation of drawings]

【図1】本発明の一実施例のシステム構成図である。FIG. 1 is a system configuration diagram of an embodiment of the present invention.

【図2】本発明方式で入口操作と出口操作を用いて相互
排除去する操作手順を示した図である。
FIG. 2 is a diagram illustrating an operation procedure for mutual exclusion using an inlet operation and an outlet operation in the method of the present invention.

【図3】入口操作の機能ブロック図である。FIG. 3 is a functional block diagram of entrance operation.

【図4】図3のロック手段の処理フロー図である。FIG. 4 is a processing flow diagram of the locking means in FIG. 3;

【図5】図3のロック切り替え手段の処理フロー図であ
る。
FIG. 5 is a processing flow diagram of the lock switching means of FIG. 3;

【図6】図3のプロセス実行状態監視手段の処理フロー
図である。
FIG. 6 is a processing flow diagram of the process execution state monitoring means in FIG. 3;

【図7】図3のプロセス実行制御手段の処理フロー図で
ある。
FIG. 7 is a processing flow diagram of the process execution control means of FIG. 3;

【図8】出口操作の処理フロー図である。FIG. 8 is a processing flow diagram of an exit operation.

【図9】従来のスピンロック方式を説明するためのシス
テム構成図である。
FIG. 9 is a system configuration diagram for explaining a conventional spin lock method.

【図10】スピンロック方式でlock操作とunlo
ck操作を用いて相互排除する操作手順を示した図であ
る。
[Figure 10] Lock operation and unlo with spinlock method
FIG. 3 is a diagram showing an operation procedure for mutual exclusion using a ck operation.

【図11】lock操作の機能ブロック図である。FIG. 11 is a functional block diagram of a lock operation.

【図12】図11のロック手段の処理フロー図である。FIG. 12 is a processing flow diagram of the locking means in FIG. 11;

【図13】unlock操作の処理フロー図である。FIG. 13 is a processing flow diagram of an unlock operation.

【図14】従来の2値セマフォ方式を説明するためのシ
ステム構成図である。
FIG. 14 is a system configuration diagram for explaining a conventional binary semaphore method.

【図15】2値セマフォ方式でP操作とV操作を用いて
相互排除する操作手順を示した図である。
FIG. 15 is a diagram showing an operation procedure for mutual exclusion using P operation and V operation in a binary semaphore system.

【図16】P操作の機能ブロック図である。FIG. 16 is a functional block diagram of P operation.

【図17】図16のロック手段、プロセス実行制御手段
の処理フロー図である。
FIG. 17 is a processing flow diagram of the lock means and process execution control means in FIG. 16;

【図18】V操作の処理フロー図である。FIG. 18 is a processing flow diagram of V operation.

【符号の説明】[Explanation of symbols]

1,2  プロセッサ 3  主記憶装置 101  プロセス制御ブロック(PCB)102  
プロセス待ちプロセス行列 103  セマフォ待ちプロセス行列 104  鍵 105  きわどい部分 106  入口操作 107  出口操作 108  例外処理プログラム 109  プロセス切り替えプログラム301  ロッ
ク手段 302  ロック切り替え手段 303  プロセス実行状態監視手段 304  プロセス実行制御手段
1, 2 Processor 3 Main storage device 101 Process control block (PCB) 102
Process waiting process queue 103 Semaphore waiting process queue 104 Key 105 Sensitive part 106 Entrance operation 107 Exit operation 108 Exception handling program 109 Process switching program 301 Lock means 302 Lock switching means 303 Process execution state monitoring means 304 Process execution control means

Claims (3)

【特許請求の範囲】[Claims] 【請求項1】  複数のプロセッサと主記憶装置がシス
テムバスで接続され、異なるプロセッサ上で同時に動作
可能な複数プロセスからなる並列プログラムが走行する
マルチプロセッサシステムにおいて、各プロセスが主記
憶装置の共有資源へアクセスする際、一時にただ一つの
プロセスしか使用できない部分(以下、きわどい部分と
呼ぶ)の実行を開始する権利(以下、実行権と呼ぶ)を
相互に排除する方式として、「きわどい部分」の実行権
を得ることに失敗したプロセスがプロセッサの使用権を
放棄して待機するスピンロック型とプロセッサの使用権
を確保したまま繰り返して実行権の獲得を試みるセマフ
ォ型とを併用し、「きわどい部分」の実行権を得るため
に待機するプロセスを、「きわどい部分」の実行権を有
するプロセスの実行状態に応じてスピンロック型あるい
はセマフォ型に切り替えることを特徴とする共有資源相
互排除方式。
Claim 1: In a multiprocessor system in which multiple processors and main memory devices are connected via a system bus, and parallel programs consisting of multiple processes that can run simultaneously on different processors run, each process uses shared resources of the main memory device. When accessing the "critical part", the right to start execution (hereinafter referred to as execution right) of a part that can only be used by one process at a time (hereinafter referred to as "critical part") is mutually excluded. The spinlock type, in which a process that fails to obtain the execution right relinquishes the right to use the processor and waits, and the semaphore type, in which the process repeatedly attempts to acquire the right to execute while securing the right to use the processor, are used together, and the A mutual exclusion method for shared resources characterized by switching a process waiting to obtain the right to execute a ``critical part'' to a spinlock type or a semaphore type depending on the execution state of the process that has the right to execute the ``critical part''.
【請求項2】  「きわどい部分」の実行権を得るため
に待機するプロセスが、「きわどい部分」の実行権を有
するプロセスのプロセス制御ブロックを自アドレス空間
内にマッピングして、その実行状態を調べることを特徴
とする請求項1記載の共有資源相互排除方式。
Claim 2: A process waiting to obtain the right to execute the "critical part" maps the process control block of the process that has the right to execute the "critical part" into its own address space and checks its execution state. 2. A shared resource mutual exclusion system according to claim 1.
【請求項3】  相互排除を行うプロセスのプログラム
の誤りを検出し、誤りを起こしたプロセスに例外処理を
実行せしめることを特徴とする請求項1もしくは2記載
の共有資源相互排除方式。
3. The shared resource mutual exclusion method according to claim 1, wherein an error in a program of a process performing mutual exclusion is detected, and the process causing the error is caused to execute exception handling.
JP14395491A 1991-05-20 1991-05-20 Shared resource mutual exclusion method for multiprocessor system Pending JPH04343143A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP14395491A JPH04343143A (en) 1991-05-20 1991-05-20 Shared resource mutual exclusion method for multiprocessor system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP14395491A JPH04343143A (en) 1991-05-20 1991-05-20 Shared resource mutual exclusion method for multiprocessor system

Publications (1)

Publication Number Publication Date
JPH04343143A true JPH04343143A (en) 1992-11-30

Family

ID=15350916

Family Applications (1)

Application Number Title Priority Date Filing Date
JP14395491A Pending JPH04343143A (en) 1991-05-20 1991-05-20 Shared resource mutual exclusion method for multiprocessor system

Country Status (1)

Country Link
JP (1) JPH04343143A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003536118A (en) * 1999-02-25 2003-12-02 サン・マイクロシステムズ・インコーポレイテッド Monitor conversion in multi-threaded computer systems

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003536118A (en) * 1999-02-25 2003-12-02 サン・マイクロシステムズ・インコーポレイテッド Monitor conversion in multi-threaded computer systems

Similar Documents

Publication Publication Date Title
JP4042945B2 (en) Interface system and method for asynchronously updating shared resources
US5579505A (en) Memory access system and method for granting or preventing atomic or nonatomic memory access requests to shared memory regions
US7962923B2 (en) System and method for generating a lock-free dual queue
JP2514299B2 (en) Serialization method of interrupt handling for process level programming
KR100976280B1 (en) Multi processor and multi thread safe message queue with hardware assistance
US5966543A (en) Method of using collaborative spinlocks to provide exclusive access to a resource in a multiprocessor computer system
US6792497B1 (en) System and method for hardware assisted spinlock
US5321825A (en) Processing system with lock spaces for providing critical section access
US5893157A (en) Blocking symbol control in a computer system to serialize accessing a data resource by simultaneous processor requests
GB2121218A (en) Shared resource locking apparatus
JPH04308961A (en) Means and apparatus for notifying state of synchronous locking of occupied process
CA2165493A1 (en) Method and apparatus for crash safe enforcement of mutually exclusive access to shared resources in a multitasking computer system
US20030149820A1 (en) Hardware semaphore intended for a multi-processor system
JP3598282B2 (en) Computer, control method thereof, and recording medium recording the control method
JPH04343143A (en) Shared resource mutual exclusion method for multiprocessor system
JPH01297760A (en) System for lock control and task control in multiprocessor
EP0297895B1 (en) Apparatus and method using lockout for synchronization of access to main memory signal groups in a multiprocessor data processing system
Atwood Concurrency in operating systems
JPH0115899B2 (en)
US20040243751A1 (en) Method for resource access co-ordination in a data processing system, data processing system and computer program
JP3603671B2 (en) Data sharing management device and data sharing management method
JPH02116949A (en) Information processing system
JPH036654A (en) Mutual exclusion system
JPH02116952A (en) Information processing system
JPH02100755A (en) Information processing system