JPH03288933A - Method for controlling access to data resources - Google Patents

Method for controlling access to data resources

Info

Publication number
JPH03288933A
JPH03288933A JP9031490A JP9031490A JPH03288933A JP H03288933 A JPH03288933 A JP H03288933A JP 9031490 A JP9031490 A JP 9031490A JP 9031490 A JP9031490 A JP 9031490A JP H03288933 A JPH03288933 A JP H03288933A
Authority
JP
Japan
Prior art keywords
lock
queue
word
control block
control
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
JP9031490A
Other languages
Japanese (ja)
Inventor
Atsushi Nitta
淳 新田
Shigeru Yoneda
茂 米田
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.)
Hitachi Ltd
Original Assignee
Hitachi Ltd
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 Hitachi Ltd filed Critical Hitachi Ltd
Priority to JP9031490A priority Critical patent/JPH03288933A/en
Publication of JPH03288933A publication Critical patent/JPH03288933A/en
Pending legal-status Critical Current

Links

Abstract

PURPOSE:To obtain a high-functional locking mechanism with minimum spin weight by separately providing a locking word to show the possibility of access and a queue control word to control a queue showing the maintaining and waiting states of the lock, and utilizing a forming function in series at a low level. CONSTITUTION:On a computer system where plural CPUs10 share a main storage device 20, plural process control blocks (PCB) 1 - PCB 4 execute locking requirements LCB 11 - LCB 34 to plural shared resources RCB 1 - RCB 3. In such a case, the locking word showing the state of the lock to the shared resource is separated from the queue control word to control the queue of the locking requirement and the access to the shared resource is efficiently formed in series among the plural processes. Thus, the high-grade locking mechanism can be realized without increasing the load of the CPU by the spin lock so much.

Description

【発明の詳細な説明】 〔産業上の利用分野〕 本発明は、データ資源に対するアクセスの制御方法、す
なわち、電子計算機上のマルチプロセス、マルチプログ
ラミング環境において、並行処理を行なうプロセス間で
データ資源を共有するためにアクセスを並列化する方法
に関し、特に、複数の命令プロセッサが主記憶装置を共
有するような密結合マルチプロセッサ環境に好適な、共
有資源に対するアクセスの制御方法に関する。
Detailed Description of the Invention [Field of Industrial Application] The present invention provides a method for controlling access to data resources, that is, a method for controlling access to data resources between processes that perform parallel processing in a multi-process, multi-programming environment on a computer. The present invention relates to a method of parallelizing access for sharing, and particularly to a method of controlling access to a shared resource suitable for a tightly coupled multiprocessor environment in which a plurality of instruction processors share a main memory.

〔従来の技術〕[Conventional technology]

電子計算機上のマルチプロセス、マルチプログラミング
環境では、多数のプロセスが様々な処理を並行して動作
できる。プロセスは、オペレーティングシステムがCP
Uを割当てるための仕事の単位であり、その動作のため
には、CPU、メモリ、Ilo等の各種資源を必要とす
る。ここで、プロセスに固定的に括り付けられている資
源の管理については、何等の問題も生じない。しかし、
複数のプロセスによって共有される資源に関しては、そ
れらの資源に対するアクセスの競合を制御し、直列化す
る何らかの方法が必要である。
In a multi-process, multi-programming environment on a computer, many processes can perform various processes in parallel. Processes are
It is a unit of work for allocating U, and its operation requires various resources such as CPU, memory, and Ilo. Here, no problem arises regarding the management of resources that are fixedly tied to processes. but,
For resources that are shared by multiple processes, some way to control and serialize contention for access to those resources is needed.

複数のプロセスによるアクセス競合を直列化する最も低
レベルの方法は、一般にリード・モディファイ・ライト
型命令と呼ばれる機械命令によって与えられる。この命
令は、主記憶上に格納された状態変数を参照し、その値
にしたがって状態変数を書き換える動作を、1つの原子
的動作として実行する。例えば、HITACMシリーズ
処理袋W(日立製作所製電子計算機)におけるC8(C
ompare and 5tzap)命令、およびCD
 S (CompareDouble and Swa
p)命令が、このような命令である。
The lowest level method for serializing access conflicts by multiple processes is provided by machine instructions commonly referred to as read-modify-write type instructions. This instruction refers to a state variable stored in main memory and executes an operation of rewriting the state variable according to its value as one atomic operation. For example, C8 (C
ompare and 5tzap) instructions, and CD
S (Compare Double and Swa
p) The instruction is such an instruction.

これらの機械命令の詳細は、(株)日立製作所発行のr
HITACMシリーズ処理装置」マニュアルに記載され
ている。
Details of these machine instructions can be found in the r published by Hitachi, Ltd.
It is described in the ``HITACM Series Processing Equipment'' manual.

リード・モディファイ・ライト型の命令においては、そ
の命令を実行するCPUが上記状態変数を参照してから
更新するまでの間、その状態変数を含む主記憶領域をロ
ックして、他CPUによる当該主記憶領域へのアクセス
をウェイトさせるという制御を、ハードウェアによって
実現している。
In a read-modify-write type instruction, the main storage area containing the state variable is locked between the time the CPU executing the instruction refers to the state variable and the time it updates it. The control of waiting access to the storage area is implemented by hardware.

ソフトウェアレイヤにおけるアクセスの直列化機構は、
上記リード・モディファイ・ライト型命令を用いて実現
される。マドニック(S、E。
The access serialization mechanism at the software layer is
This is realized using the above-mentioned read-modify-write type instructions. Madnick (S, E.

Madnick)およびトノパン(J 、 J 、Do
novan)による“オペレーティング システムズ(
OperatingSystems)” (1974月
刊、 McGrat++−8111社)の4.5章に示
されているように、このような機構は典型的には、「ロ
ックJおよび「アンロック」と呼ばれる命令系列からな
る。
Madnick) and Tonopan (J, J, Do
“Operating Systems (
As shown in Chapter 4.5 of ``Operating Systems'' (Monthly 1974, McGrat++-8111), such a mechanism typically consists of a series of instructions called ``Lock J'' and ``Unlock''.

この機構においては、ある共有資源が使用中であるかど
うかを表示するために、ロックワードと呼ばれる資源対
応の状態変数が設けられる。
In this mechanism, a resource-compatible state variable called a lockword is provided to indicate whether a certain shared resource is in use.

ロック動作では、ロック要求プロセスは、ロックワード
を参照して、もし使用中でなければロックワードを使用
中に変更し、もし使用中であれば。
In a lock operation, the lock requesting process looks at the lock word and changes the lock word to in use if it is not in use.

再びロック動作を試行する(このロック動作の操り返し
はスピンウェイトと呼ばれる)。アンロック動作におい
ては、プロセスは、ロックワードを使用中から非使用中
に変更する。この方法では。
Attempt the locking action again (this reversal of the locking action is called a spin-wait). In an unlock operation, the process changes the lock word from in use to not in use. in this way.

ロックを確保しているプロセスは、共有資源に対して排
他的な使用権を有し、他のプロセスはロック保有プロセ
スがアンロックを行なうまで、共有資源にアクセスでき
ない。
The process that has secured the lock has exclusive usage rights to the shared resource, and other processes cannot access the shared resource until the process that holds the lock unlocks it.

ロック動作は、ロックワードを参照・更新するために、
リード・モディファイ・ライト型命令を使用する。これ
は、あるプロセスが、ロックワードが使用中でないと判
定してからロックワードを使用中に変更する処理の間に
、他プロセスがロックワードを書き換えてしまうことを
防ぐためである。
The lock operation is performed in order to refer to and update the lock word.
Use read-modify-write type instructions. This is to prevent another process from rewriting the lock word while a certain process determines that the lock word is not in use and changes the lock word to be in use.

このようなロック機構は、しばしばスピンタイプのロッ
クあるいは簡単にスピンロックと呼ばれる。
Such locking mechanisms are often referred to as spin-type locks or simply spinlocks.

ソフトウェアによるロック機構には、上記スピンロック
の他に、サスペンドタイプのロック(もしくはサスペン
ドロック)と呼ばれるものがある。
In addition to the above-mentioned spin lock, there is also a lock mechanism based on software called a suspend type lock (or suspend lock).

サスペンドロックのロック動作においては、ロックが即
時に確保できない場合、ロック要求プロセスは先入れ先
出しのキューに入れられ、サスペンド状態となる。すな
わち、ロック要求プロセスは、ロック待ちの間に、スピ
ンウェイト処理によってCPUを占有することなく、C
PUを他の実行可能なプロセスに明は渡す。アンロック
動作実行プロセスは、新たにロック確保が可能となるプ
ロセスがキュー中に存在すれば、そのプロセスをキュー
から取り出してサスペンド状態を解除する。サスペンド
ロックは、スピンロックに比べて、CPUを有効に利用
することが可能であるが、キュー操作とプロセスの状態
変更処理の余分な動作を必要とする。また、一般にキュ
ーは、主記憶上に設けられたプロセス対応の制御ブロッ
クをポインタチエージで結ぶことによって実現されるが
、このポインタチェーン自体が、ロック動作およびアン
ロック動作を並行して行なう複数のプロセスによってア
クセスされる共有資源であり、アクセスの直列化を必要
とする。このキュー操作のアクセスの直列化は、スピン
ロックによって実現されることが多かった。
In the suspend lock locking operation, if the lock cannot be secured immediately, the lock requesting process is placed in a first-in, first-out queue and placed in a suspended state. In other words, the lock request process uses the CPU while waiting for the lock without occupying the CPU with spin wait processing.
Light passes the PU to another executable process. If a process that can newly secure a lock exists in the queue, the unlock operation execution process takes that process out of the queue and releases the suspended state. Suspend locks can utilize the CPU more effectively than spinlocks, but require extra operations for queue manipulation and process state change processing. In addition, a queue is generally realized by linking process-compatible control blocks provided in main memory by pointer chaining, but this pointer chain itself consists of multiple locking and unlocking operations performed in parallel. A shared resource that is accessed by processes and requires serialization of access. This serialization of access for queue operations was often achieved using spinlocks.

特開昭60−128537には、スピンロックに依存す
ることなく、リード・モディファイ・ライト型命令を直
接使用して、サスペンドロックを実現する方法が示され
ている。この方法においては、ロックワードは、アクセ
スの可能性を示すロックフラグと、ロック待ちのプロセ
スを表現するキューのアンカとなるロックポインタから
なり、ロックワード全体をリード・モディファイ・ライ
ト型の命令で参照・更新することによって、排他および
共有の2つのモードを備えたロック機構を実現している
Japanese Patent Application Laid-Open No. 60-128537 discloses a method for realizing a suspend lock by directly using read-modify-write type instructions without relying on spinlocks. In this method, a lock word consists of a lock flag that indicates the possibility of access and a lock pointer that serves as an anchor for a queue that represents a process waiting for a lock, and the entire lock word is referenced by a read-modify-write type instruction. - By updating, a locking mechanism with two modes, exclusive and shared, is realized.

〔発明が解決しようとする課題〕[Problem to be solved by the invention]

上記の単純なスピンロック方法では、ロック確保要求の
競合が発生した場合、ロックを確保できた、ただ工つの
プロセスを実行するCPUを除いては、CPUがスピン
ウェイト処理に使用され、本来の業務処理が中断される
。これは、特に、複数の命令プロセッサが主記憶装置を
共用するような、いわゆる密結合マルチプロセッサ環境
においては、無視できない業務処理性能の低下を引き起
こす。スピンロックは、オペレーティングシステムの最
も基本的で単純な処理の直列化に使われる人きものであ
り、より高レベルの複雑な処理の逐次化には向いていな
い。
In the simple spinlock method described above, when a conflict of lock acquisition requests occurs, the CPUs, except for the CPU that was able to secure the lock and executes the simple process, are used for spin-wait processing and are not used for the original work. Processing is interrupted. This causes a considerable deterioration in business processing performance, particularly in a so-called tightly coupled multiprocessor environment in which a plurality of instruction processors share the main memory. Spinlocks are used to serialize the most basic and simple operations in operating systems, and are not suitable for serializing higher-level complex operations.

す、スペントロック方法は、スピンロックより処理が複
雑であるが、ロック待ちのプロセスがCPUを占有する
ことがないため、高レベル処理の逐次化に適している。
Although the spent lock method has more complicated processing than the spin lock method, it is suitable for serializing high-level processing because the process waiting for the lock does not occupy the CPU.

しかし、サスペンドロック処理要求が頻発するようにな
ると、ロック待ちのキュー操作を逐次化するためのスピ
ンロックによる性能劣化が顕著になってくる。
However, when suspend lock processing requests occur frequently, performance degradation due to spin locks for serializing lock wait queue operations becomes noticeable.

上記特開昭60−128537に開示された方法を用い
ると、スピンロックを用いることなく、共用および排他
の2つのロックモードを備えたサスペンドタイプのロッ
クを実現でき、高レベル処理の逐次化を効率よく行なう
ことができる。しかし、単なる共用・排他の2モードの
ロックだけでは、ソフトウェア階層のより上位の処理に
おける、複雑な逐次化機能の要求に対応できない。1つ
のロックワード内に、共有資源の占有状態を表示するロ
ックフラグと、ロック待ちを管理するキューのアシカポ
インタを設け、ロックフラグとロックポインタをまとめ
てリード・モディファイ・ライト型命令によって参照・
更新することが、実現可能なロック機能に対する制限を
もたらす。これは、ロックワードの長さに制約が存在す
るためである。
By using the method disclosed in JP-A-60-128537, a suspend-type lock with two lock modes, shared and exclusive, can be realized without using spinlocks, and high-level processing can be serialized efficiently. can do well. However, mere two-mode locking (shared/exclusive) cannot meet the demands of complex serialization functions in higher-level processing in the software hierarchy. A lock flag that displays the shared resource occupancy status and a sea lion pointer for a queue that manages lock waiting are provided in one lock word, and the lock flag and lock pointer can be referenced together by read/modify/write type instructions.
Updating introduces limitations on the locking functionality that can be achieved. This is because there is a restriction on the length of the lock word.

典型的なハードウェアで実現されているリート・モディ
ファイ・ライト型命令は、倍語長以下の主記憶領域を操
作するものであり、通常アンカポインタは1語を占有す
るため、ロックフラグは1語長以内で表現されなければ
ならない。これは、多種多様なロックモードを表現する
場合に、大きな制約となる。
A read-modify-write type instruction implemented in typical hardware operates on a main memory area of double word length or less, and the anchor pointer usually occupies one word, so the lock flag only occupies one word. Must be expressed within the length. This becomes a major constraint when expressing a wide variety of lock modes.

またこの方法では、ロック待ちを管理するキューの操作
において、キューの最後の1つまたは連続する複数の要
素を、リード・モディファイ・ライト型命令を用いて、
要素のネクストポインタを更新することにより削除して
いる。この方法は、キュー要素の削除を行なうプロセス
が、同時にはただ1つしか存在しないという前提のもと
でだけ正しく動作する。共用・排他の2モードのロック
では、キュー要素の削除は、ロックモートの変わり目と
なるアンロック処理時、すなわち、排他ロック解放、ま
たは最後の共用ロックの解放時にだけ実行されるため、
上記前提条件が満たされる。
In addition, in this method, in the operation of the queue that manages lock waiting, the last one or several consecutive elements of the queue are read, modified, and written using a read/modify/write type instruction.
It is deleted by updating the next pointer of the element. This method works only under the assumption that there is only one process at a time that is deleting queue elements. In two-mode locks (shared/exclusive), queue elements are deleted only during unlock processing at the time of lock mode change, that is, when an exclusive lock is released or when the last shared lock is released.
The above prerequisites are met.

しかし、より複雑なロック機能では、このような前提条
件は必ずしも満足されず、複数のアンロック処理実行プ
ロセスがキューを同時に操作するタイミングが発生しう
る。もちろん、この2モードロツク方法を、内部的な制
御ブロック操作の逐次化に利用することにより、より高
機能なロック処理プログラムを作成することが可能であ
る。しかし、低レベルの機能(すなわちリード・モデイ
フアイ・ライト型命令)を直接利用して、高機能なロッ
ク方法を実現できるならば、その方が望ましい。
However, with more complex locking functions, such prerequisites are not necessarily satisfied, and there may be times when multiple unlock processing execution processes operate on the queue simultaneously. Of course, by using this two-mode locking method to serialize internal control block operations, it is possible to create a more sophisticated locking program. However, it would be preferable if a high-performance locking method could be implemented by directly using low-level functions (ie, read-modify-write type instructions).

本発明は、以下のような背景のもとに考案されたもので
あり、その目的は、高レベルの機能を備えたソフトウェ
アロック機構を、できるだけ低レベルの直列化機能を利
用して、効率的に実現することである。
The present invention was devised against the following background, and its purpose is to efficiently implement a software locking mechanism with high-level functionality by utilizing as low-level serialization functionality as possible. The goal is to achieve this goal.

〔課題を解決するための手段〕[Means to solve the problem]

本発明の目的は、アクセス可能性を示すロックワードと
、ロックの保有および待ち状態を示すキューを管理する
キューコントロールワードを分離して設け、キューコン
トロールワードは、キューへの要素の追加をカウントす
る追加カウンタと、最後にキューに入れられた要素を指
すキューアンカポインタを含むようにして、ロックワー
ドおよびキューコントロールワードを以下のように参照
・更新することによって実現できる; (1)ロック処理は、ロックワードを参照してロック確
保が即時に可能か、それとも待たなければならないかを
判断し、ロック要求をキューに登録し、もしロックを待
つのであれば、キュー登録後、ロックワードを参照して
ロック確保が可能力)どう力\再度確認し、ロック確保
可能であればアンロック処理の一部を実行してロック待
ちを回避する。
An object of the present invention is to separately provide a lock word indicating accessibility and a queue control word for managing a queue indicating lock holding and waiting state, and the queue control word counts addition of elements to the queue. This can be accomplished by referencing and updating the lock word and queue control word, including an additional counter and a queue anchor pointer pointing to the last queued element, as follows: (1) Lock processing is performed using the lock word Determine whether the lock can be acquired immediately or if it is necessary to wait by referring to , register the lock request in the queue, and if you want to wait for the lock, after registering the lock, refer to the lock word and secure the lock. If possible, check again and if the lock can be secured, execute part of the unlock process to avoid waiting for the lock.

(2)アンロック処理は、はずキューコントロールワー
ドの追加カウンタを記憶し、ロック許可処理を実行し、
追加カウンタの値を、先に記憶しておいたカウンタ値と
比較して、もし変更されていたら、アンロック処理を再
試行する。
(2) The unlock process stores the additional counter of the hazuku cue control word, executes the lock permission process, and
The value of the additional counter is compared with the previously stored counter value, and if it has been changed, the unlocking process is retried.

(3)ロック許可処理は、キューを走査してロック許可
が可能な待ち状態のロック要求を確保し、ロックワード
を新しいロック状態に更新し、ロック待ちを解除する。
(3) Lock permission processing scans the queue to secure waiting lock requests for which lock permission can be granted, updates the lock word to a new lock state, and releases the lock request.

また、本発明の目的は、キューコントロールエリアに、
キューアクセスに対する排他・共用ロックを示すキュー
ロックフラグを設け、また、キュー要素に削除された要
素であることを示す削除フラグを設け、以下のようにキ
ュー操作を行なうことによって実現される: (1)キューへの要素の追加は、キューアンカポインタ
へ、追加要素のアドレスを設定し、追加カウンタをカウ
ントアンプすることによって行なう。
Further, an object of the present invention is to provide a cue control area with
This is achieved by providing a queue lock flag indicating an exclusive/shared lock for queue access, providing a deletion flag for a queue element indicating that it is a deleted element, and performing queue operations as follows: (1 ) An element is added to the queue by setting the address of the added element to the queue anchor pointer and incrementing the addition counter.

(2)キューからの要素の削除では、キューに対する共
用ロックを確保して、キューを走査し、削除すべき要素
に削除フラグを設定して、キューに対する共用ロックを
解放する。この時、キューに対する共用ロックを最後に
解放するプロセスが、共用ロックの解放と同時にキュー
に対する排他ロックを確保し、削除フラグが設定されて
いる要素を実際にキューから削除する。キューに対して
排他ロックが設定されている場合、キューに対する共用
ロック要求はスピンウェイトする。
(2) When deleting an element from a queue, a shared lock on the queue is secured, the queue is scanned, a deletion flag is set on the element to be deleted, and the shared lock on the queue is released. At this time, the process that is the last to release the shared lock on the queue simultaneously releases the shared lock and secures an exclusive lock on the queue, and actually deletes the element for which the deletion flag has been set from the queue. If an exclusive lock is set on a queue, a shared lock request on the queue will spin-wait.

〔作用〕[Effect]

共有資源に対するロックの状態を示すロックワードと、
ロック要求のキューを管理するキューコントロールワー
ドを分離したことによって、複雑なロック機能を実現す
ることが容易になる。すなわち、ロックワードおよびキ
ューコントロールワードはそれぞれ、本発明が適用され
るコンピュータシステムのハードウェアによって規定さ
れる、リード・モディファイ・ライト型命令が扱える最
大のオペランド長まで占有できるようになる。
A lock word indicating the state of a lock on a shared resource;
By separating the queue control word that manages the queue of lock requests, it becomes easier to implement complex locking functions. That is, the lock word and queue control word can each occupy up to the maximum operand length that can be handled by a read-modify-write type instruction, which is defined by the hardware of the computer system to which the present invention is applied.

一方、ロックワードとキューコントロールワードを分離
して、別々に更新するため、ロックワードの状態とキュ
ーの状態との整合性をとるための機構が必要となる。ロ
ック処理時の、キューイング後のロックワード再確認と
、アンロック処理時の、キューコントロールワード中の
追加カウンタの記憶および確認が、このような機構を与
える。
On the other hand, since the lock word and queue control word are separated and updated separately, a mechanism is required to ensure consistency between the state of the lock word and the state of the queue. The revalidation of the lock word after queuing during lock processing and the storage and verification of additional counters in the queue control word during unlock processing provide such a mechanism.

ロック処理時のロックワード再確認は、ロックワードを
参照してから、キューイングするまでの間に、アンロッ
ク処理によって、ロックワードが変更されたことを検出
する。また、アンロック処理時の追加カウンタの操作は
、キューを走査してロック許可可能なロック要求を確定
している間に、新たな待ち状態のロック要求がキューに
追加されたことを検出する。これによって、ロック処理
とアンロック処理が競合して、ロック許可可能であるに
もかかわらず、待ち状態が解除されないロツり要求が発
生してしまうタイミングを救済できる。
Lock word reconfirmation during lock processing detects that the lock word has been changed by unlock processing after the lock word is referenced and before queuing. Further, the operation of the additional counter during unlock processing detects that a new pending lock request is added to the queue while scanning the queue to determine lock requests that can be granted lock. As a result, it is possible to relieve the timing in which a locking process and an unlocking process conflict and a locking request is not released from the waiting state even though locking is possible.

一方、キューコントロールワードの排他・共用ロック方
法は、非常に少ないスピンウェイトで、−射的なキュー
操作を行なうことを可能とする。
On the other hand, the exclusive/shared locking method of the queue control word makes it possible to perform morphometric queue operations with very little spin wait.

キューへの要素の追加は、キューコントロールワードを
、直接リード・モディファイ・ライト型命令で操作する
ことによって実行され、キュー要素への削除フラグの設
定は、キューに対する共用ロックを確保して実行される
。これらの処理は、複数のプロセスによって同時に実行
可能である。特に、アンロック処理で複数のプロセスが
ロック許可処理のためにキューを同時にアクセスするこ
とが可能となる。共用ロックを最後に解放するプロセス
は、共用ロックの解放と同時に、キューに対する排他ロ
ックを確保し、キュー中の排他フラグが設定されている
要素をキューから実際にはずして、排他ロックを解放す
る。この、排他ロック占有の間に、他プロセスがアンロ
ック処理を実行しようとして、キューをアクセスする場
合はスピンウェイトするが、このような競合が発生する
確率は十分に低いことが期待できる。
Adding elements to a queue is performed by manipulating the queue control word directly with read-modify-write type instructions, and setting a deletion flag on a queue element is performed by securing a shared lock on the queue. . These processes can be executed simultaneously by multiple processes. In particular, unlock processing allows multiple processes to simultaneously access the queue for lock grant processing. The process that is the last to release the shared lock simultaneously acquires an exclusive lock on the queue, actually removes the elements in the queue with the exclusive flag set from the queue, and releases the exclusive lock. During exclusive lock occupancy, if another process attempts to perform unlock processing and accesses the queue, it will spin-wait, but it can be expected that the probability of such contention occurring is sufficiently low.

以上のように、本発明によれば、最小限のスピンウェイ
トの上に、高機能なロック機構を実現することができる
As described above, according to the present invention, a highly functional locking mechanism can be realized with a minimum spin weight.

〔実施例〕〔Example〕

以下、本発明の実施例を図に基づいて詳細に説明する。 Hereinafter, embodiments of the present invention will be described in detail based on the drawings.

ここでは、2つの実施例を述べる。第1の実施例におい
ては、全てのロック要求、すなわち、許可されているロ
ック要求と、待たされているロック要求の双方が、キュ
ーに保持される。第2の実施例においては、待たされて
いるロック要求だけで、キューに保持される。
Two examples will be described here. In the first embodiment, all lock requests, both granted and pending lock requests, are held in a queue. In the second embodiment, only pending lock requests are held in the queue.

(1)第1の実施例 (1−1)コントロールブロックの構成第1図は、本発
明の第1の実施例の概要を示すコンピュータシステムの
ブロック図である。第1図では、プロセスが共有資源に
対してロックを要求して許可されている。または待たさ
れている、状態が、主記憶(もしくは仮想記憶)上の制
御ブロック群と、それらの間のポインタチェーンによっ
て表現されている。共有資源はリソースコントロールブ
ロック(RCB)100によって、プロセスはプロセス
コントロールブロック(PCB)110によって、ロッ
ク要求はロックコントロールブロック(LCB)120
によって、それぞれ示される。共有資源100に対する
ロック要求120は、ポインタチェーン140によって
、最新に発せられたロック要求から順につながれる。
(1) First Embodiment (1-1) Configuration of Control Block FIG. 1 is a block diagram of a computer system showing an outline of a first embodiment of the present invention. In FIG. 1, a process requests and is granted a lock on a shared resource. The state of waiting is expressed by a group of control blocks in main memory (or virtual memory) and a chain of pointers between them. Shared resources are handled by a resource control block (RCB) 100, processes are handled by a process control block (PCB) 110, and lock requests are handled by a lock control block (LCB) 120.
are shown respectively. Lock requests 120 for the shared resource 100 are connected by a pointer chain 140 in order from the most recently issued lock request.

また、プロセス110が行ったロック要求120は、ポ
インタチェーン150によってつながれる。
Further, the lock requests 120 made by the process 110 are linked by a pointer chain 150.

すなわち、ロック要求120が、どのプロセスからの、
どの共有資源に対する要求であるかということが、2種
類のポインタチェーン140および150によって一意
的に特定される。
That is, from which process is the lock request 120 issued?
The two types of pointer chains 140 and 150 uniquely specify which shared resource the request is for.

第2図に、本発明が実施されるコンピュータシステムの
環境と、制御ブロック間のポインタチェーンの実例を示
す。第2図では、複数のCPU10 (CPUI−CP
Un)が、主記憶装置20を共有しているコンピュータ
システム上で、複数のプロセスPCB 1〜PCB4が
、複数の共有資源RCB−RCB3に対してロック要求
LCB11〜LCB34を行っている様子が示されてい
る。本発明は、このような、複数のCPUが主記憶装置
を共有する密結合マルチプロセッサシステムでのマルチ
プログラミング環境において、複数のプロセス間の共有
資源へのアクセスを効率的に直列化する方法を与える。
FIG. 2 shows an example of a computer system environment in which the present invention is implemented and a pointer chain between control blocks. In FIG. 2, a plurality of CPUs 10 (CPUI-CP
Un) shows that on a computer system sharing the main storage device 20, a plurality of processes PCB1 to PCB4 are making lock requests LCB11 to LCB34 to a plurality of shared resources RCB to RCB3. ing. The present invention provides a method for efficiently serializing access to shared resources among multiple processes in such a multiprogramming environment in a tightly coupled multiprocessor system in which multiple CPUs share a main memory. .

本発明は、また、CPUが1台であるようなコンピュー
タシステムでのマルチプログラミング環境において、複
数プロセスの共有資源へのアクセスを直列化する場合に
も、有効である。
The present invention is also effective when serializing access to shared resources by multiple processes in a multiprogramming environment in a computer system with one CPU.

第2図に示すポインタチェーンのうち、横方向のチェー
ンは、特定の共有資源に対するロック要求のキューを表
す。例えば、RCBIからLCBll、LCB12.L
CB14に延びるポインタチェーンは、RCBIによっ
て代表される共有資源に対するロック要求を、要求発生
時間の新しい順につなぐものである。LCB中に(wa
it)表示のあるものは、そのロック要求が現在待ち状
態であることを示す。第2図では、RCBIに対して最
も古くに発行されたロック要求LCB14は許可された
が、その後に発行されたロック要求LCB12とLCB
IIは、即時にロックが許可されず、ロック要求LCB
14が解放されるのを待っている状態が示されている。
Among the pointer chains shown in FIG. 2, the horizontal chain represents a queue of lock requests for specific shared resources. For example, from RCBI to LCBll, LCB12. L
The pointer chain extending to the CB 14 connects lock requests for the shared resource represented by the RCBI in the order of request generation time. During LCB (wa
it) An indication indicates that the lock request is currently pending. In FIG. 2, the oldest lock request LCB14 issued to the RCBI was granted, but the lock requests LCB12 and LCB issued after that were granted.
II, the lock is not granted immediately and the lock request LCB
14 is shown waiting to be released.

RCB2およびRCB 3から右方向に延びるポインタ
チェーンについても同様である。
The same goes for the pointer chains extending rightward from RCB2 and RCB3.

これに対し、縦方向のポインタチェーンは、特定のプロ
セスが発行したロック要求のリストを表す。例えば、P
CB 1からLCBII、LCB31へと延びるポイン
タチェーンは、PCBlによって示されるプロセスが、
ロック要求LCB11、LCB31を、これとは逆順に
発行した事を示す。ロック要求31は許可されたが、ロ
ック要求11は許可されず、プロセスPCB 1は、現
在待ち状態である。PCB2.PCB3.PCB4から
下方向に延びるポインタチェーンも同様である。1つの
プロセスは、0以上の任意の数だけ許可されたロック要
求を待つことができるが、待ちのロック要求は高々1つ
しか待てない。
In contrast, a vertical pointer chain represents a list of lock requests issued by a particular process. For example, P
The pointer chain extending from CB 1 to LCBII to LCB31 indicates that the process indicated by PCBl is
This indicates that lock requests LCB11 and LCB31 were issued in the reverse order. Lock request 31 was granted, lock request 11 was not granted, and process PCB 1 is currently in a waiting state. PCB2. PCB3. The same goes for the pointer chain extending downward from PCB4. One process can wait for any number of granted lock requests greater than or equal to zero, but it can wait for at most one lock request.

ここで再び第1図にもどって、各制御ブロックの詳細を
説明する。
Now, returning to FIG. 1 again, details of each control block will be explained.

共有資源を代表するリソースコントロールブロック(R
CB)100は、共有資源に対するロックの状態を示す
ロックワードLWと、共有資源に対するロック要求のキ
ューを管理するキューコントロールワードQCWを含む
。ここで、本発明の1つの特徴は、LWとQCWが隣接
している必要がないことである。ロックワードLWの内
容の詳細については、後述する。キューコントロールワ
ードQCWは、排他フラグX、共有カウンタSHR。
A resource control block (R
CB) 100 includes a lock word LW that indicates the status of a lock on a shared resource, and a queue control word QCW that manages a queue of lock requests for the shared resource. Here, one feature of the present invention is that the LW and QCW do not need to be adjacent. Details of the contents of the lock word LW will be described later. The queue control word QCW includes an exclusive flag X and a shared counter SHR.

削除フラグD7追加カウンタADD、キューアンカポイ
ンタANCからなる。排他フラグXと共用カウンタSH
Rは、複数プロセスによって同時にアンロック処理が行
われる場合の、キューに対するアクセスの直列化を制御
するために用いられる。
Deletion flag D7 consists of addition counter ADD and queue anchor pointer ANC. Exclusive flag X and shared counter SH
R is used to control serialization of access to the queue when unlock processing is performed simultaneously by multiple processes.

削除フラグDは、キュー中に、ポインタチェーンにはつ
ながっているが、論理的には削除されているLCBが存
在することを示すために用いられる。
The deletion flag D is used to indicate that there is an LCB in the queue that is connected to the pointer chain but has been logically deleted.

追加カウンタADDは、LCBが新たにキューに入れら
れるごとにカウントアツプされ、ロック処理とアンロッ
ク処理の競合が発生したことを検出するために用いられ
る。キューアンカポインタANCは、ロック要求のキュ
ーを表すポインタチェーン140の始点である。
The additional counter ADD is incremented each time an LCB is newly placed in the queue, and is used to detect the occurrence of a conflict between lock processing and unlock processing. Queue anchor pointer ANC is the start of a pointer chain 140 representing a queue of lock requests.

プロセスを代表するプロセスコントロールブロック(P
CB)110は、そのプロセスに対して許可されている
、または、許可されるのを待っているロック要求のリス
トを表すポインタチェーン150の始点となるポインタ
LPTを含む。
Process control block (P
CB) 110 contains a pointer LPT that is the start of a pointer chain 150 representing a list of lock requests that have been granted or are waiting to be granted to the process.

ロック要求を表すロックコントロールブロック(LCB
)120は、RCBからのポインタチェーン140にお
ける次のLCBを示すポインタNIQと、PCBからの
ポインタチェーン150における次のLCBを示すポイ
ンタNISと、要求しているロックのモードを示すMO
DEと、フラグFLGを含む。フラグFLGは、LCB
の状態を示すものであり、ロック要求が待ち状態である
ことを意味するWフラグ、LCBがキューすなわちRC
Bからのポインタチェーン140内で、無効であること
を意味するエフラグ、ロック要求が許可可能となって待
ち状態を解除する必要があることを意味するPフラグを
含む。LCBは、また、待ち状態を解除する必要がある
ロック要求をつなぐポインタチェーン160における次
のLCBを示すポインタNIPを含む。
Lock control block (LCB) representing a lock request
) 120 is a pointer NIQ indicating the next LCB in the pointer chain 140 from RCB, a pointer NIS indicating the next LCB in the pointer chain 150 from PCB, and MO indicating the mode of the lock requested.
Contains DE and flag FLG. Flag FLG is LCB
The W flag indicates that the lock request is in a waiting state, and the LCB is in the queue, that is, the RC
The pointer chain 140 from B includes an ef flag, meaning invalid, and a P flag, meaning the lock request can be granted and needs to be released from the wait state. The LCB also contains a pointer NIP pointing to the next LCB in the pointer chain 160 that connects the lock requests that need to be released from the wait state.

ロック処理/アンロック処理は1以上のコントロールブ
ロックの他に、いくつかのワークレジスタ130を使用
する。ワークレジスタの1つは、待ち状態解除を行なう
べきロック要求をつなぐポインタチェーン160の始点
となるポインタPPTとして使われる。もう−っのワー
クレジスタは、アンロック処理中で、新たに許可可能と
なったロック要求のモードを記憶するためのΔMODE
として使われる。
Lock processing/unlock processing uses several work registers 130 in addition to one or more control blocks. One of the work registers is used as a pointer PPT that is the starting point of a pointer chain 160 that connects lock requests to be released from a wait state. The other work register is ΔMODE, which is used to store the mode of lock requests that can be newly granted during unlock processing.
used as.

第3図は、ロックワードLWの内容を示している。本実
施例におけるロックは、E U/E R/PU/PR/
SU/SRの6種類のモードを待つ。
FIG. 3 shows the contents of the lock word LW. The locks in this embodiment are EU/ER/PU/PR/
Wait for 6 different modes: SU/SR.

第4図は、これらのロックモード間の両立性を示す。第
4図のマトリクス中でO印は2つのモードが同時に許可
可能であることを、x印は、2つのモードが背反である
ことをそれぞれ示している。
FIG. 4 shows the compatibility between these locking modes. In the matrix of FIG. 4, the O symbol indicates that two modes can be permitted simultaneously, and the X symbol indicates that the two modes are mutually exclusive.

このマトリクスかられかるように、E U/E R/P
Uモードのロックは、ただ1つのプロセスにだけ許可さ
れ、PR/SU/SRモードのロックは同時に複数のプ
ロセスに許可されうる。このため、第3図のロックワー
ドLW中では、E U/E R/PUモードは、各々フ
ラグによって、PR/SU/SRモードは各々カウンタ
によって表現される。
As you can see from this matrix, E U/E R/P
U mode locks are granted to only one process, and PR/SU/SR mode locks can be granted to multiple processes at the same time. Therefore, in the lock word LW of FIG. 3, the EU/E R/PU modes are each represented by flags, and the PR/SU/SR modes are each represented by counters.

ロックワードLWは、また、許可を待っているロック要
求の数を示すカウンタWA I Tを含む、1つでも待
ちのロック要求が存在する場合、その後に到着したロッ
ク要求は全て待ちとなる。これは。
The lock word LW also includes a counter WA I T indicating the number of lock requests waiting to be granted; if there is even one lock request waiting, all lock requests that arrive after that are placed waiting. this is.

ロック要求の時間順序性を保証するためである。This is to ensure the time order of lock requests.

ロックモードの種類、およびロックモードのロックワー
ドLW中における表現方法については、第3図および第
4図に示したものに限らず、任意のものが可能である。
The type of lock mode and the method of expressing the lock mode in the lock word LW are not limited to those shown in FIGS. 3 and 4, but any other method is possible.

ここでのただ1つの制限は、ロックワードLWが、リー
ド・モディファイ・ライト型の命令によって、更新可能
であるということである。
The only restriction here is that the lockword LW can be updated by read-modify-write type instructions.

(l−2)C3およびCDS命令 ロック処理/アンロック処理の詳細に入る前に、そこで
使用されるリード・モディファイ・ライト型機械命令で
あるC S (Compare and Swap)命
令とCD S (Compare Double an
d Swap)命令について簡単に説明しておく。
(l-2) C3 and CDS Instructions Before going into details of lock processing/unlock processing, we will explain the C S (Compare and Swap) instruction and CD S (Compare Double), which are read-modify-write machine instructions used therein. an
dSwap) command will be briefly explained below.

C8命令は、2つの汎用レジスタと主記憶(仮想記憶)
上の1語長の領域をオペランドとし、第1のレジスタと
主記憶(仮想記憶)上の1語の内容を比較して、もし両
者が等しければ、その1語を第2のレジスタの内容で書
き換えて条件コードをOに設定し、もし両者が異なれば
、第1のレジスタにその1語の内容をロードして条件コ
ードを1に設定する動作を、原子的な1動作として実行
する、リード・モディファイ・ライト型の命令である。
The C8 instruction uses two general-purpose registers and main memory (virtual memory).
Using the one-word length area above as an operand, compare the contents of one word in the first register and main memory (virtual memory), and if they are equal, replace that one word with the contents of the second register. Rewrite and set the condition code to O, and if they are different, load the contents of that one word into the first register and set the condition code to 1, which is executed as one atomic operation.・This is a modify write type instruction.

CDS命令も、CS命令と同様の動作を実行するが、こ
ちらは、4つの汎用レジスタを用いて倍語長の領域を操
作するところが異なる。複数のCPUが主記憶を共有す
る密結合マルチプロセッサでは、あるCPUが実行中の
プロセスが主記憶上の状態変数の内容を比較し、その値
に従ってその状態変数を変更しようとする場合に、通常
のロード/コンベア/ストア命令を使用したのでは、状
態変数を読み込んで(ロード)、比較して(コンベア)
、書き換える(ストア)処理の間に、状態変数が他のC
PUによって書き換えられ、処理の整合性が失われてし
まうことがありうる。このためC8命令やCDS命令を
使用して、比較と書き換えを原子的な1動作で行うよう
にするのである。
The CDS instruction also performs the same operation as the CS instruction, but this instruction differs in that it uses four general-purpose registers to operate on a double-length area. In a tightly coupled multiprocessor where multiple CPUs share main memory, when a process being executed by one CPU compares the contents of a state variable in main memory and attempts to change the state variable according to the value, Using the load/conveyor/store instructions, we read the state variables (load) and compare them (conveyor).
, during the rewriting (store) process, the state variable is changed to another C
It may be rewritten by the PU and the consistency of processing may be lost. For this reason, a C8 instruction or a CDS instruction is used to perform comparison and rewriting in one atomic operation.

以下で、ロック処理/アンロック処理を、流れ図に基づ
いて詳細に説明する。なお、説明が不必要に複雑になる
ことを避けるため、図では細かな初期設定処理や例外処
理を省いである。
The lock processing/unlock processing will be explained in detail below based on a flowchart. Note that detailed initial setting processing and exception handling are omitted in the diagram to avoid making the explanation unnecessarily complicated.

(1−3)ロック処理 第5図は、ロック処理の流れ図である。ロックを要求す
るプロセスは、入力情報として、RCBアドレス、PC
Bアドレス、要求ロックモードを措定して、ロック処理
をコールする。ロック処理では、まずLCBを作成して
、その内容を初期化し、PCBからのポインタチェーン
につなぐ(ステップ1001)。この初期化では、NI
QおよびNIPは空値に、フラグは全てリセット状態に
(1-3) Lock processing FIG. 5 is a flow chart of lock processing. The process requesting the lock receives the RCB address, PC
Assign the B address and request lock mode, and call the lock process. In the locking process, an LCB is first created, its contents are initialized, and it is connected to the pointer chain from the PCB (step 1001). In this initialization, the NI
Q and NIP are set to null values, and all flags are reset.

MODEは要求ロックモードに設定される。また、LC
BをPCBからのポインタチェーンにつなぐため、NI
Sには旧LPTの値が、新LPTとしてLCBアドレス
が、それぞれセットされる。
MODE is set to request lock mode. Also, L.C.
To connect B to the pointer chain from the PCB, NI
The value of the old LPT is set in S, and the LCB address is set as the new LPT.

次に、ロックワードLWを参照して、要求したロックが
許可可能か、待たなければならないかを判定しくステッ
プ1002) 、CDS命令を用いて新しいロックワー
ドをセットする(ステップ1003)。待ち状態のロッ
ク要求が存在せず、かつ、要求したロックモードが既に
他のプロセスに許可されているロックモードと両立可能
な場合にだけロックが許可される。新たなロックワード
は、ロック許可可能な場合は、要求ロックモードに対応
するフラグをセットする、もしくはカウンタを上げるこ
とにより、ロック待ちの場合は、WAITカウンタを上
げることによって得られる。
Next, referring to the lock word LW, it is determined whether the requested lock can be granted or whether it must be waited for (step 1002), and a new lock word is set using the CDS instruction (step 1003). A lock is granted only if there are no pending lock requests and the requested lock mode is compatible with lock modes already granted to other processes. A new lock word can be obtained by setting a flag corresponding to the requested lock mode or incrementing a counter if the lock can be granted, or by incrementing the WAIT counter if the lock is waiting.

ステップ1003のCDS命令が失敗するのは。Why does the CDS instruction in step 1003 fail?

他プロセスのロック処理(ステップ1003)もしくは
アンロック処理(後述の第7図ステップ1207)によ
るロックワードLWの更新とのアクセス競合が発生した
ためであり、ステップ1.OO2から再試行する(ステ
ップ1004)。ロック待ちが必要であればLCBのW
フラグをセットする(ステップ1005.ステップ10
06)。
This is because an access conflict with the update of the lock word LW by another process's locking process (step 1003) or unlocking process (step 1207 in FIG. 7, described later) has occurred, and step 1. Try again from OO2 (step 1004). If you need to wait for a lock, use LCB's W.
Set the flag (step 1005. Step 10
06).

続いて、CDS命令を用いて、LCBをキューに入れる
(ステップ1007)。この処理は、現在のANCの値
をNIQにコピーした後、CDS命令を用いて、QCW
の内容が他プロセスによって変更されていないことを確
かめながら、ANCの値をLCBアドレスに書き換え、
かつADDカウンタの値を1だけ増加させることによっ
て実行される。ADDカウンタが最大値である場合には
、lへラップアラウンドする。ステップ1007のCD
S命令が失敗するのは、他プロセスのロック処理(ステ
ップ1007)またはアンロック処理(後述の第6図ス
テップ1107、第8図ステンプ1302.1304)
によるQCWの更新と競合が発生したためであり、キュ
ーイング処理を再試行する(ステップ1008)。
Subsequently, a CDS instruction is used to queue the LCB (step 1007). This process copies the current ANC value to NIQ, then uses the CDS instruction to
Rewrite the ANC value to the LCB address while making sure that the contents have not been changed by other processes.
This is executed by increasing the value of the ADD counter by one. If the ADD counter is at the maximum value, it wraps around to l. Step 1007 CD
The S instruction fails because of lock processing (step 1007) or unlock processing (step 1107 in FIG. 6, steps 1302 and 1304 in FIG. 8, described later) of other processes.
This is because a conflict with the QCW update has occurred, and the queuing process is retried (step 1008).

LCBをキューに入れた後、ロックが許可されるならば
ロック処理コール元にリターンし、ロック待ちが必要な
らばモードの再確認を行なう(ステップ1009)。モ
ード再確認処理では、再びロックワードを参照してロッ
クが許可可能になっているかどうか確かめ(ステップ1
010、ステップ1011)、ロック許可がやはり不可
能である場合はロック要求プロセスを待ち状態にする(
ステップ1012)。もし、ロックワードが許可可能に
変更されている場合は、ロック待ちを回避するためにア
ンロック2処理をコールする(ステップ1013)。こ
のようなモード再確認を行うのは、ステップ1003で
ロックワードをセットしてから、ステップ1007でL
CBをキューにつなぐまでの間に、現在ロックを許可さ
れているプロセスがアンロック処理を実行してロックワ
ードLWが、ロック許可可能な状態に書き換えられた時
、今回のロック要求が待ちのままでキューに残る事を防
ぐためである。LCBがキューにつながれていれば、ア
ンロック処理がキューを走査して待ちのLCBを見つけ
ることができ、ロック待ちは解除される。ロック処理で
ロックワードを参照する以前に、アンロック処理でのロ
ックワード更新が行われていれば、ロック要求は待ちに
ならないさ 問題は、競合するアンロック処理がロックワードを更新
する以前に、ロック処理でロックワード・を参照し、か
つ、ロック処理でLCBをキューにつなぐ以前にアンロ
ック処理でキューを走査する、というタイミングで2つ
の処理が実行された場合である。この場合、アンロック
処理によって、このLCBの待ちが解除されることは期
待できないため、LCBのキュー登録後にロック処理内
でモードを再確認し、必要であればアンロック処理を模
擬するのである。
After placing the LCB in the queue, if locking is permitted, the process returns to the lock processing caller, and if locking is required, the mode is reconfirmed (step 1009). In the mode reconfirmation process, the lock word is referenced again to confirm whether the lock can be granted (step 1).
010, step 1011), and if lock grant is still not possible, place the lock requesting process in a waiting state (
Step 1012). If the lock word has been changed to allow permission, unlock 2 processing is called to avoid waiting for the lock (step 1013). This kind of mode reconfirmation is performed after setting the lock word in step 1003 and then setting L in step 1007.
Until the CB is connected to the queue, if the process currently granted the lock executes the unlock process and the lock word LW is rewritten to a state where the lock can be granted, the current lock request remains waiting. This is to prevent it from remaining in the queue. If the LCB is queued, the unlock process can scan the queue to find the waiting LCB, and the lock wait is released. If the lock word is updated in the unlock process before the lock word is referenced in the lock process, the lock request will not wait.The problem is that before the conflicting unlock process updates the lock word, This is a case where two processes are executed at the same time as the lock word is referenced in the lock process, and the queue is scanned in the unlock process before the LCB is connected to the queue in the lock process. In this case, it cannot be expected that the waiting state of this LCB will be released by the unlock process, so the mode is reconfirmed during the lock process after the LCB is registered in the queue, and if necessary, the unlock process is simulated.

従来の方法では、ロックワードLWとキューコントロー
ルワードQCWは、一体化されており、1回のCDS命
令で同時に更新されていたため、このようなタイミング
の挟間が発生することはなかった。本発明では、ロック
の自由度を増大するために、ロックワードLWとキュー
コントロールワードQCWを分離しており、そのために
、モード再確認処理が必要となったのである。
In the conventional method, the lock word LW and the queue control word QCW were integrated and updated simultaneously by one CDS instruction, so such a timing gap did not occur. In the present invention, the lock word LW and queue control word QCW are separated in order to increase the degree of freedom of locking, and therefore, mode reconfirmation processing is required.

(1−4)アンロック処理 第6図〜第9図に、アンロック処理の流れを示す。アン
ロック処理は、2つのエントリポイントを持つ。ロック
を許可されたプロセスが、そのロックを解放する場合に
コールするのがアンロック1エントリポイントである。
(1-4) Unlocking process FIGS. 6 to 9 show the flow of the unlocking process. The unlock process has two entry points. The unlock 1 entry point is called when a process that has been granted a lock releases the lock.

これに対し、前述したロック処理のモード再確認処理(
ステップ1013)においてコールされるのがアンロッ
ク2エントリポイントである。入力情報は、双方のエン
トリポイントともLCBアドレスである。
On the other hand, the lock processing mode reconfirmation process (
The unlock 2 entry point is called in step 1013). The input information is the LCB address for both entry points.

第6図は、アンロック処理の初期部の流れである。通常
のアンロック処理、すなわちアンロック1エントリポイ
ントから始まる処理では、まずワークレジスタΔMOD
Eに、ロック解放によって発生するロックワードLWの
変更分、すなわちLCBのMODEの逆数をセットする
(ステップ1101)。次にCS命令を用いてLCBの
■フラグをセットする(ステップ1102)。このC8
命令は、■フラグのセットが成功するまで繰り返される
(ステップ1103)。続いて、LCBをPCBからの
ポインタチェーンよりはずす(ステップ1104)。す
なわち、このLCBがポインタチェーンの先頭であれば
LPTに、そうでなければこのLCBの1つ前のLCB
のNISに、このLCBのNISの値をコピーする。以
上がアンロック1エントリポイントに個有の前処理であ
り、以後の処理はアンロック2エントリポイントと共通
である。アンロック2エントリポイントから処理が開始
された場合、ワークレジスタΔMODEの初期値は0で
ある。
FIG. 6 shows the flow of the initial part of the unlock process. In normal unlock processing, that is, processing starting from the unlock 1 entry point, first the work register ΔMOD
The change in the lock word LW caused by the lock release, that is, the reciprocal of the MODE of LCB is set in E (step 1101). Next, the CS instruction is used to set the ■ flag of the LCB (step 1102). This C8
The instruction is repeated until the ■ flag is successfully set (step 1103). Subsequently, the LCB is removed from the pointer chain from the PCB (step 1104). In other words, if this LCB is the head of the pointer chain, it is used as the LPT, otherwise it is used as the LCB immediately before this LCB.
Copy the NIS value of this LCB to the NIS of this LCB. The above is the preprocessing unique to the unlock 1 entry point, and the subsequent processing is common to the unlock 2 entry point. When processing is started from the unlock 2 entry point, the initial value of the work register ΔMODE is 0.

次に、ロックワードLW、およびキューコントロールワ
ードQCW内のADDカウンタの値を、空きのワードレ
ジスタまたはワークエリアに退避しくステップ1105
)、Xフラグがセットされているかを見る(ステップ1
106)。Xフラグがセットされていることは、他プロ
セスがキューを占有してアクセスを行っていることを意
味しており、Xフラグがリセットされるまでスピンウェ
イトする。Xフラグがリセットされていることを確認し
たら、CDS命令でキューコントロールワードQCWの
SHRをカウントアツプする(ステップ1107)。こ
のCDS命令が成功した場合、アンロック処理実行プロ
セスは、キューに対する共有アクセス権限を得たことに
なる。CDS命令が失敗するのは、他プロセスによるロ
ック処理またはアンロック処理とのQCW更新における
競合が発生したためであり、ステップ1105から再試
行する(ステップ1108)。ここまでが。
Next, in step 1105, the values of the ADD counter in the lock word LW and queue control word QCW are saved to a free word register or work area.
), check if the X flag is set (step 1
106). The fact that the X flag is set means that another process is occupying the queue and accessing it, and will spin-wait until the X flag is reset. After confirming that the X flag has been reset, the SHR of the queue control word QCW is counted up using the CDS command (step 1107). If this CDS instruction is successful, the unlock processing execution process has obtained shared access authority to the queue. The reason why the CDS instruction fails is because there is a conflict in the QCW update with lock processing or unlock processing by another process, and the process is retried from step 1105 (step 1108). That's it so far.

アンロック処理の第1段階である。This is the first stage of the unlock process.

第7図は、許可が可能となったロック要求をキュー中で
見けて、待ちを解除する処理の流れである。この処理は
、キューコントロールワードQCWのANCポインタか
らポインタチェーンをたどり、最も古くに待ち状態とな
ったLCBを捜すことから始まる(ステップ1201)
。すなわち、Wフラグがセットされ、かつ、■フラグと
Pフラグがリセットされているような、ポインタチェー
ン中の最も後ろのLCBを見つける。許可可能なロック
要求がもはや存在しない場合、このような状態のLCB
は見つからず、ループ終了処理に移る(ステップ120
2)。
FIG. 7 is a flowchart of a process in which a lock request that can be granted is found in a queue and released from waiting. This process begins by tracing the pointer chain from the ANC pointer of the queue control word QCW and searching for the LCB that entered the wait state the oldest (step 1201).
. That is, find the last LCB in the pointer chain in which the W flag is set and the {circle around (2)} flag and P flag are reset. If there are no longer any grantable lock requests, the LCB in such a state
is not found, and the process moves to loop termination processing (step 120
2).

待ちを解除すべきLCBが見つかったならば。If an LCB to be released from the wait state is found.

C8命令でLCBにPフラグをセットする(ステップ1
203)。C8命令が成功すれば(ステップ1204)
、ロックワードの差分情報をワークレジスタΔMODE
に加え(ステップ1205)、LCBをワークレジスタ
PPTからのポインタチェーンにつなぐ(ステップ12
06)。ΔMODEの変更では、WAITカウンタを1
減し、LCBが要求するロックモードに対応するフラグ
のセット。
Set the P flag in the LCB with the C8 instruction (step 1
203). If the C8 instruction is successful (step 1204)
, the difference information of the lock word is stored in the work register ΔMODE.
(step 1205), and connects the LCB to the pointer chain from the work register PPT (step 12
06). When changing ΔMODE, set the WAIT counter to 1.
set the flag corresponding to the lock mode requested by the LCB.

もしくはカウンタの増分を行なう。また、LCBのNI
Pに現在のPPTの値をコピーし、PPTにこのLCB
のアドレスをセットすることによって、LCBをPPT
からのポインタチェーンにっなぐことかできる。ステッ
プ1203のC8命令が失敗するのは、LCBのフラグ
FLGに対するアクセスの競合が起きた場合であり、ス
テップ1201から処理を再試行する。
Or increment the counter. Also, LCB's NI
Copy the current PPT value to P and add this LCB to PPT.
By setting the address of PPT
You can connect to a pointer chain from . The C8 instruction in step 1203 fails when a conflict occurs in accessing the flag FLG of the LCB, and the process is retried from step 1201.

ステップ1206までの処理が完了したら、待ちを解除
すべき次のLCBを捜すため、ステップ1201にもど
る。このようにして、ΔMODEには、ロックワードを
変更するための差分情報が累積され、PPTからのポイ
ンタチェーンには、待ちを解除すべきLCBのリストが
形成される。
When the processing up to step 1206 is completed, the process returns to step 1201 to search for the next LCB to be released from the waiting state. In this way, differential information for changing the lock word is accumulated in ΔMODE, and a list of LCBs to be released from waiting is formed in the pointer chain from PPT.

LCBサーチのループから抜けると、ΔMODEに蓄積
されたモード差分情報を用いて新しいロックワード内容
を作り、CDS命令でロックワードLWにセットする(
ステップ1207)。この場合、CDS命令でLWと比
較するのは、ステップ1105で退避しておいたロック
ワードの内容である。このCDS命令が失敗するのは、
ステップ1105からステップ12o7までの間に他プ
ロセスがLWを更新したためであり、再び、ループの先
頭(ステップ1201)にもどって、待ちが解除できる
LCBがないか確かめる(ステップ1208)。CDS
命令が成功したならば、PPTからのポインタチェーン
につながれているLCBの待ちを全て解除しくステップ
1209)、第8図のアンロック終了処理に制御を移す
When exiting the LCB search loop, new lock word contents are created using the mode difference information accumulated in ΔMODE, and set in the lock word LW with the CDS instruction (
Step 1207). In this case, what is compared with the LW in the CDS instruction is the content of the lock word saved in step 1105. This CDS instruction fails because
This is because another process updated the LW between step 1105 and step 12o7, and the process returns to the beginning of the loop (step 1201) to check whether there is any LCB that can be released from the wait state (step 1208). CDS
If the instruction is successful, all waits for the LCBs connected to the pointer chain from the PPT are released (step 1209), and control is transferred to the unlock termination process shown in FIG.

第8図は、アンロック処理の終了部の流れである。ここ
では、ステップ1107で確保したキューに対する共用
アクセス権限の解放処理を行なう。
FIG. 8 shows the flow of the end portion of the unlock process. Here, the shared access authority for the queue secured in step 1107 is released.

まず、QCWのSHRカウンタの内容を見て(ステップ
1301)、キューにアクセスしている他プロセスが存
在する、すなわちSHRの値が1よりも大きい場合は、
CDS命令を用いてSHHの値を減じる(ステップ13
02)。もし、アンロック処理1エントリポイントから
処理が開始されているのであったならば、このCDS命
令で同時にDフラグをセットする。CDS命令が成功す
ればアンロック処理を終了してコールもとヘリターンす
る(ステップ1303)。一方、キューをアクセスして
いるプロセスが自プロセスだけの場合、SHRの値は1
である。この場合は、CDS命令を用いてSHRの値を
減じると同時にXフラグをセットする(ステップ130
4)。もし、アンロック処理1エントリポイントから処
理が開始されている場合には、やはり、Dフラグを同時
にセットする。ステップ1304のCDS命令が成功し
てQCWにXフラグをセットするということは、キュー
に対する排他アクセス権限を確保できたことを意味する
。この場合、第9図のLCB削除処理に制御を移す(ス
テップ1305)。
First, check the contents of the SHR counter of the QCW (step 1301), and if there is another process accessing the queue, that is, if the SHR value is greater than 1,
Decrease the value of SHH using the CDS instruction (step 13
02). If the process has been started from the unlock process 1 entry point, the D flag is set at the same time by this CDS instruction. If the CDS command is successful, the unlock process is completed and the process returns to the source of the call (step 1303). On the other hand, if the only process accessing the queue is the own process, the SHR value is 1.
It is. In this case, use the CDS instruction to reduce the value of SHR and set the X flag at the same time (step 130
4). If the process is started from the unlock process 1 entry point, the D flag is also set at the same time. The fact that the CDS instruction in step 1304 is successful and sets the X flag in the QCW means that exclusive access authority to the queue has been secured. In this case, control is transferred to the LCB deletion process shown in FIG. 9 (step 1305).

ステップ1302もしくはステップ1304のCDS命
令が失敗するのは、他プロセスによるロック処理または
アンロック処理とのQCWアクセスの競合が発生した場
合である。どちらの処理と競合したかを確認するために
、ADDの値が、ステップ1105で退避した値と等し
いかどうかを見る(ステップ1306)。ADDの値が
変わっていなければ、他プロセスのアンロック処理との
競合であり、ステップ1301からQCWの更新処理を
再試行すればよい。ADDの値が変わっていれば、他プ
ロセスによるロック処理と競合が発生したためであり、
ステップ1201からキュー走査処理全体をもう一度行
う必要がある。ロック処理によってADDが更新された
ということは、新たなLCBがキューに追加されたこと
を意味する。このLCBが、ロック許可可能な、待ち状
態のLCBではないかどうかを確認するために、キュー
走査を再試行するのである。このようなLCB状態が発
生するのは、まずロック処理がロックワードLWを参照
して待ちを決定しくステップ1002)、次にアンロッ
ク処理がキューを走査して待ちを解除可能なLCBを捜
しくステップ1201〜ステツプ1206)、その後に
ロック処理がLCBをキューに追加してプロセスを待ち
状態にしくステップ1007〜ステツプ1012)、最
後にアンロック処理が上記待ちロック要求を許可可能と
するようなモードにロックワードを更新する(ステップ
1207)、というタイミングで2つの処理が同時実行
される場合である。ロック処理がLCBをキューに追加
するよりも、アンロック処理がロックワードを更新する
方が先であれば、ロック処理のモード再確認処理(ステ
ップ1010)が、競合発生を検出してLCBの待ちを
解除する。このように、ロック処理におけるモード再確
認動作と、アンロック処理におけるADDカウンタ確認
動作の双方を備えることによって、ロック要求が不要に
待たされるタイミングが発生することを防止できる。
The CDS instruction in step 1302 or step 1304 fails when a QCW access conflict with lock processing or unlock processing by another process occurs. In order to confirm with which process the conflict occurred, it is checked whether the value of ADD is equal to the value saved in step 1105 (step 1306). If the value of ADD has not changed, there is a conflict with the unlock process of another process, and the QCW update process can be retried from step 1301. If the value of ADD has changed, it is because a conflict with lock processing by another process has occurred.
The entire queue scanning process from step 1201 needs to be performed again. The fact that ADD has been updated by lock processing means that a new LCB has been added to the queue. The queue scan is retried to check whether this LCB is not a waiting LCB that can be granted a lock. This LCB state occurs because the lock process first refers to the lock word LW and decides to wait (step 1002), and then the unlock process scans the queue to find an LCB that can release the wait. Steps 1201 to 1206), then the lock process adds the LCB to the queue and puts the process in a waiting state (steps 1007 to 1012), and finally the unlock process allows the waiting lock request to be granted. This is a case where two processes are executed simultaneously at the timing of updating the lock word (step 1207). If the unlock process updates the lock word earlier than the lock process adds the LCB to the queue, the lock process mode reconfirmation process (step 1010) detects the occurrence of a conflict and waits for the LCB. Release. In this way, by providing both the mode reconfirmation operation in the lock process and the ADD counter confirmation operation in the unlock process, it is possible to prevent the occurrence of a timing in which a lock request is made to wait unnecessarily.

最後に、第9図にしたがって、LCBのキューからの削
除処理を説明する。まず、QCWのDフラグを参照して
、キュー中に削除すべきLCBが存在するか判定する(
ステップ1401)。Dフラグがセットされていなけれ
ば、Xフラグをリセットしてアンロック処理を終了する
(ステップ14.12)。Dフラグがセットされている
場合には、ANCからポインタチェーンをたどって最初
のLCBを得る(ステップ1402)。最初のLCBの
■フラグがセットされていれば、C3命令でそのLCB
をキューからはずして(ステップ1404゜ステップ1
409) 、LCBをメモリの空き領域として解放する
(ステップ1411)。先頭のLCBをキューからはず
すのは、LCBのNIQの値をANCに設定することに
よって行う。ステップ1409のC8命令が失敗するの
は、他プロセスのQCW更新処理との競合した場合であ
り、ステップ1402から処理を再試行する(ステップ
1410)。ステップ1411でLCBを解放した場合
も1次のLCBを得るためにステップ1402にもどる
。このようにして、ANCの指す先頭のLCBが存在し
なくなった場合は、ループを抜ける(ステップ1403
)。
Finally, the process of deleting an LCB from the queue will be described with reference to FIG. First, it is determined whether there is an LCB to be deleted in the queue by referring to the D flag of the QCW (
Step 1401). If the D flag is not set, the X flag is reset and the unlocking process ends (step 14.12). If the D flag is set, the pointer chain is followed from the ANC to obtain the first LCB (step 1402). If the ■ flag of the first LCB is set, that LCB is
from the queue (step 1404゜step 1)
409), the LCB is released as a free memory area (step 1411). The first LCB is removed from the queue by setting the NIQ value of the LCB to ANC. The C8 instruction in step 1409 fails when there is a conflict with the QCW update process of another process, and the process is retried from step 1402 (step 1410). Even if the LCB is released in step 1411, the process returns to step 1402 to obtain the primary LCB. In this way, if the first LCB pointed to by ANC no longer exists, the loop exits (step 1403
).

先頭のLCBのXフラグがセットされていない場合は、
NIQをたどって次のLCBを得(ステップ1405)
、そのLCBのエフラグがセットされていたら(ステッ
プ1407)、LCBをキューからはずして解放する(
ステップ1408)。
If the X flag of the first LCB is not set,
Obtain the next LCB by following the NIQ (step 1405)
, if the LCB's eff flag is set (step 1407), the LCB is removed from the queue and released (
step 1408).

この場合、1つ前のLCBのNIQに、はずすべきLC
BのNIQをコピーすることによって、キューからの削
除が実行される。ここでのNIQの更新にC8命令を用
いる必要はない。このようにして、キューの最後のLC
Bまで処理が進んだらループから抜ける(ステップ14
06)。
In this case, the LC to be removed is set to the NIQ of the previous LCB.
Dequeuing is performed by copying B's NIQ. There is no need to use the C8 instruction to update NIQ here. In this way, the last LC in the queue
When the process progresses to B, the loop is exited (step 14).
06).

アンロック処理では、キュー中の任意の位置のLCBが
削除および解放される可能性があるため、キューのポイ
ンタ操作を行なうプロセスを、ただ1つに限定する必要
がある。LCBの削除処理はQCWのXフラグをセット
して実行するため、他プロセスのアンロック処理による
キュー操作と競合してポインタチェーンが不正になるこ
とはない。
In the unlock process, an LCB at an arbitrary position in the queue may be deleted and released, so it is necessary to limit the number of processes that operate the queue pointer to only one. Since the LCB deletion process is executed by setting the QCW X flag, there is no possibility that the pointer chain will become invalid due to conflict with the queue operation due to the unlock process of another process.

他プロセスのアンロック処理は、Xフラグがリセットさ
れるまでスピンウェイトする(ステップ工工05〜ステ
ップ1106)、X7ラグは、SHRを1からOに変更
するプロセス、すなわち、並行してキューアクセスを行
っていた複数のプロセスのうちで最後にキューアクセス
を終了するプロセスによってだけセットされ、Xフラグ
がセットされたLCBのキューからの削除が終ると直ち
にリセットされる。したがって、スピンウェイトが発生
する確立は非常に小さいものである。一方、ロック処理
によるキューアクセスの競合は、ステップ1409のC
8命令で検出する。ロック処理では、キューに対するア
クセスがANCへの新LCBの追加に限定されているた
め、スピンウェイトを用いないでアンロック処理キュー
操作と処理を直列化することができるのである。
The unlock processing of other processes spins wait until the X flag is reset (step 05 to step 1106). It is set only by the process that is the last to finish queue access among the multiple processes that were in progress, and is reset immediately after the LCB for which the X flag has been set has been deleted from the queue. Therefore, the probability that spin weight will occur is very small. On the other hand, queue access contention due to lock processing is caused by C in step 1409.
Detected with 8 instructions. In lock processing, access to the queue is limited to adding new LCBs to the ANC, so unlock processing queue operations and processing can be serialized without using spin waits.

(2)第2の実施例 第10図は、本発明の第2の実施例の概要を示すコンピ
ュータシステムのブロック図である。第2の実施例が第
1の実施例と異なる点は、第2の実施例においては、L
CBは、もはやあるプロセスがロックを許可されている
状態を示す役目を持たずに、ロック待ち表すためだけに
用いられることである。したがって、各プロセスには高
々1個のLCBLか対応せず、PCB、およびPCBか
らLCBをつなぐポインタチェーンは不要となる。
(2) Second Embodiment FIG. 10 is a block diagram of a computer system showing an outline of a second embodiment of the present invention. The difference between the second embodiment and the first embodiment is that in the second embodiment, L
CB no longer has the role of indicating a state in which a certain process is permitted to hold a lock, but is used only to indicate that a process is waiting for a lock. Therefore, each process corresponds to at most one LCBL, and a PCB and a pointer chain connecting the PCB to the LCB are not required.

RCBやワークレジスタに関しては、第1の実施例と同
様である。
The RCB and work registers are the same as in the first embodiment.

第2の実施例におけるロック処理およびアンロック処理
は、キューにLCBを登録するのが、ロック待ちの場合
だけであることを除いては、第1の実施例とほぼ同様で
あり、ここで詳しく述べることはしない。第5図におい
て、ステップ1001を削除し、ステップ1005でY
ESの場合は即時にリターンし、ステップ1006でL
CBを作成するように処理を変更すれば、第2の実施例
におけるロック処理の流れ図が得られる。同様に、第6
図において、全てのアンロック処理をアンロック2エン
トリポイントから開始するようにし、第7図において、
ステップ↓203でLCBのPフラグと同時にDフラグ
もセットするように処理の流れを変更すれば、第2の実
施例におけるアンロック処理の流れ図が得られる。
The lock processing and unlock processing in the second embodiment are almost the same as in the first embodiment, except that the LCB is registered in the queue only when waiting for a lock, and will be described in detail here. I have nothing to say. In FIG. 5, step 1001 is deleted and Y is selected in step 1005.
In the case of ES, return immediately, and in step 1006 L
If the process is changed to create a CB, a flowchart of the lock process in the second embodiment can be obtained. Similarly, the sixth
In the figure, all unlock processing is started from the unlock 2 entry point, and in Figure 7,
If the process flow is changed to set the D flag at the same time as the P flag of the LCB in step ↓203, the flow chart of the unlock process in the second embodiment can be obtained.

〔発明の効果〕〔Effect of the invention〕

以上のように、本発明によれば、複雑なモードを備えた
ロック機構を、リード・モディファイ・ライト型命令と
最小限のスピンロックだけによって効率的に実現するこ
とができる。特に、複数のCPUが主記憶を共有するよ
うな、密結合マルチプロセッサ環境において、スピンロ
ックによるCPUの負荷増大をあまり発生させずに、高
度なロック機能を実現できる効果がある。
As described above, according to the present invention, a locking mechanism with complicated modes can be efficiently realized using only read-modify-write type instructions and a minimum number of spinlocks. Particularly in a tightly coupled multiprocessor environment where multiple CPUs share main memory, an advanced locking function can be achieved without significantly increasing the load on the CPU due to spin locks.

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

第1図は本発明の第1の実施例を示すコンピュータシス
テムのブロック図、第2図は本発明が有効に働く計算機
環境と主記憶内容を示したブロック図、第3図はロック
ワードの詳細の説明図、第4図はロックワードの両立性
マトリクスの説明図、第5図はロック処理の流れ図、第
6図から第9図はアンロック処理の流れ図、第10図は
本発明の第2の実施例を示すコンピュータシステムのブ
ロック図である。 10・・・CPU、20・・・主記憶(仮想記憶)装置
、100・・リソースコントロールブロック(RCB)
、110・・・プロセスコントロールブロック(PCB
)、120・・・ロックコントロールブロック(LCB
)、130・・・ワークレジスタ、140・・・ANC
ポインタチェーン、150・・・LPTポインタチェー
ン、第2図 第1図 第3図 第4図 ロック両立性マトリクス (1)モードの1文字目=他プロセスに許可する処理S
 (Shared)   :  リード/ライトを許す
P (Protected)  :  リードは許すが
ライトは許さないE (Exclusive)  : 
 リード/ライh ’−!’f Eない(2〉モードの
2文字目=自プロセスで行なう処理R(ReLriev
e)    リードを行なうU(υpdate)   
・ リード/ライ]・を行なう第6図 第5図 第7図 第8図 第9図
Fig. 1 is a block diagram of a computer system showing a first embodiment of the present invention, Fig. 2 is a block diagram showing the computer environment and main memory contents in which the invention effectively operates, and Fig. 3 is a detailed diagram of the lock word. FIG. 4 is an explanatory diagram of a lock word compatibility matrix, FIG. 5 is a flowchart of the locking process, FIGS. 6 to 9 are a flowchart of the unlocking process, and FIG. 10 is a diagram of the second embodiment of the present invention. 1 is a block diagram of a computer system illustrating an embodiment of the present invention. 10... CPU, 20... Main memory (virtual memory) device, 100... Resource control block (RCB)
, 110...Process control block (PCB)
), 120...Lock control block (LCB
), 130...work register, 140...ANC
Pointer chain, 150...LPT pointer chain, Figure 2 Figure 1 Figure 3 Figure 4 Lock compatibility matrix (1) 1st character of mode = Process S allowed to other processes
(Shared): Permit read/write P (Protected): Permit read but not write E (Exclusive):
Lead/Lie h'-! 'f E not (2> 2nd character of mode = process R (ReLriev
e) U to read (υpdate)
・ Lead/Lie] Figure 6 Figure 5 Figure 7 Figure 8 Figure 9

Claims (1)

【特許請求の範囲】 1、多重プロセス、多重プログラミングシステムにおい
て、複数のプロセスによつて共有されるデータ資源への
アクセスを、各プロセスが発行するロック要求を許可す
るかまたは待たせることによつて制御する方法であつて
、共有資源およびロック要求に対応する制御ブロックを
設け、該共有資源に対応する制御ブロックは、共有資源
のロック状態を示すロックワードと、ロック要求に対応
する制御ブロックを含むキューを管理するキューコント
ロールワードを持ち、該キューコントロールワードはあ
る時点からある時点の間にキユーへロツク要求に対応す
る制御ブロックが追加されたことを検出する手段を含み
、(1)ロックワードを参照してロックが許可されるか
どうかを判定し、次にロック要求に対応した制御ブロッ
クをキューに追加し、もしロ ック待ちが必要な場合はロックワードを再び参照して、
ロック要求が許可可能な状態に変更されていたらロック
待ちを回避するステップと、 (2)キューを走査して許可可能なロック要求を見つけ
、新たに許可されたロック要求に対応するようにロック
ワードを更新し、ロック待ちを解除し、キュー走査開始
点からロック待ち解除時点の間に、ロック要求に対応す
る制御ブロックが、キューに追加されたことを検出した
ならば、キュー走査から処理を再試行するステップ、 を備えることを特徴としたデータ資源に対するアクセス
を制御する方法。 2、多重プロセス、多重プログラミングシステムにおい
て、複数のプロセスによつて共有されるデータ資源への
アクセスを、各プロセスが発行するロック要求を許可す
るかまたは待たせることによつて制御する方法であつて
、共有資源およびロック要求に対応する制御ブロックを
設け、該共有資源に対応する制御ブロックは、共有資源
のロック状態を示すロックワードと、ロック要求に対応
する制御ブロックを含むキューを管理するキューコント
ロールワードを持ち、該キューコントロールワードは最
後にキューに入れられた制御ブロックを指すアンカポイ
ンタと、キューに制御ブロックが入れられた回数を記録
する追加カウンタとを含み、ロック要求に対応する制御
ブロックはキューに1つ先に入れられた制御ブロックを
指すポインタと、要求しているロックの種別を示すワー
ドと、ロック要求が待たされていることを示すウェイト
フラグを含むことを特徴としたデータ資源に対するアク
セスを制御する方法。 3、請求項2においてさらに、 (1)ロックワードを参照してロック要求が許可可能か
どうかを判断するステップと、 (2)ロック要求に対応する制御ブロックをキューに追
加して、上記追加カウンタを増分するステップと、 (3)上記キューへの制御ブロックの追加後、ロック待
ちが必要であれば、ロックワードを再び参照して、ロッ
クワード内容がロック許可可能に変更されていないかを
確認し、もし許可可能であれば、ロック待ちの回避を行
なうステップ、 を備えることを特徴としたデータ資源に対するアクセス
を制御する方法。 4、請求項3においてさらに、 (1)キューコントロールワードの追加カウンタを退避
するステップと、 (2)キューを走査してロック許可可能な制御ブロック
のリストを作成するステップと、 (3)許可されるべきロックに応じてロックワードを変
更するステップと、 (4)上記(1)において退避した追加カウンタと現在
の追加カウンタを比較し、もし異なつていれば上記(1
)から処理を再試行するステップと、 (5)上記(2)で作成された制御ブロックのリスト中
のロック待ちを解除するステップ、 を備えることを特徴としたデータ資源に対するアクセス
を制御する方法。 5、請求項2においてさらに、キューコントロールワー
ドは、キューに対する専用アクセスの可能性を表す排他
フラグと、キューに対する共用アクセスの可能性を表す
共用カウンタを含み、ロック要求に対応する制御ブロッ
クは、キュー中の制御ブロックが論理的に削除されたこ
とを表す無効フラグを含み、 (1)排他フラグがセットされていなければ、共用カウ
ンタを増分してキュー走査を開始し、排他フラグがセッ
トされていればリセットされるのを待つステップと、 (2)キュー走査を行つて目的の制御ブロックに無効フ
ラグをセットするステップと、 (3)共用カウンタを減じた結果が1以上の場合は共用
カウンタを減じてキュー走査を終了し、0になる場合は
共用カウンタを減じると同時に排他フラグをセットして
キューを走査し、無効フラグが設定された制御ブロック
をキューから削除し、排他フラグをリセットしてキュー
走査を終了するステップ、 を備えることを特徴としたデータ資源に対するアクセス
を制御する方法。 6、請求項1から請求項5のいずれかに示されたデータ
資源に対するアクセスを制御する方法を備えたコンピュ
ータシステム。
[Claims] 1. In a multi-process, multi-programming system, access to a data resource shared by multiple processes is granted or made to wait for a lock request issued by each process. A control method, wherein a control block corresponding to a shared resource and a lock request is provided, and the control block corresponding to the shared resource includes a lock word indicating a lock state of the shared resource and a control block corresponding to the lock request. The queue control word has a queue control word for managing the queue, the queue control word includes means for detecting that a control block corresponding to a lock request is added to the queue between a certain point in time, and (1) a lock word is added to the queue. It references it to determine whether the lock is granted, then adds the control block corresponding to the lock request to the queue, and if it needs to wait for a lock, it references the lock word again.
(2) scanning the queue to find a grantable lock request and setting a lock word to correspond to the newly granted lock request; (2) scanning the queue to find a grantable lock request; If it is detected that a control block corresponding to the lock request has been added to the queue between the queue scan start point and the lock wait release point, processing is restarted from queue scan. A method for controlling access to a data resource, comprising the steps of: attempting. 2. A method for controlling access to data resources shared by multiple processes in a multi-process, multi-programming system by granting or making lock requests issued by each process wait. , a control block corresponding to a shared resource and a lock request is provided, and the control block corresponding to the shared resource is a queue control that manages a queue including a lock word indicating the lock state of the shared resource and a control block corresponding to the lock request. a control block corresponding to a lock request, the queue control word having an anchor pointer pointing to the last enqueued control block and an additional counter recording the number of times the control block was enqueued; A data resource characterized in that it includes a pointer to a control block placed in a queue earlier, a word indicating the type of lock being requested, and a wait flag indicating that the lock request is being waited for. How to control access. 3. Claim 2 further provides the steps of: (1) determining whether the lock request can be granted by referring to the lock word; and (2) adding a control block corresponding to the lock request to a queue and counting the additional counter. (3) After adding the control block to the above queue, if it is necessary to wait for a lock, refer to the lock word again and check whether the contents of the lock word have been changed to allow locking. and, if permissible, avoiding lock waits. 4. Claim 3 further provides the steps of: (1) saving an additional counter for the queue control word; (2) scanning the queue to create a list of control blocks for which locking is permitted; and (3) locking is permitted. (4) Compare the additional counters saved in (1) above with the current additional counters, and if they are different, change the lock word in accordance with the lock word (1) above.
); and (5) releasing the lock waiting state in the list of control blocks created in (2) above. 5. Claim 2 further provides that the queue control word includes an exclusive flag representing the possibility of exclusive access to the queue and a shared counter representing the possibility of shared access to the queue, and the control block corresponding to the lock request (1) If the exclusive flag is not set, increment the shared counter and start scanning the queue; (2) performing a queue scan and setting an invalid flag in the target control block; and (3) decrementing the shared counter if the result of decrementing the shared counter is 1 or more. If it becomes 0, the shared counter is decremented, the exclusive flag is set and the queue is scanned, the control block with the invalid flag set is deleted from the queue, the exclusive flag is reset, and the queue is scanned. A method for controlling access to a data resource, comprising: terminating a scan. 6. A computer system comprising a method for controlling access to data resources according to any one of claims 1 to 5.
JP9031490A 1990-04-06 1990-04-06 Method for controlling access to data resources Pending JPH03288933A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP9031490A JPH03288933A (en) 1990-04-06 1990-04-06 Method for controlling access to data resources

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP9031490A JPH03288933A (en) 1990-04-06 1990-04-06 Method for controlling access to data resources

Publications (1)

Publication Number Publication Date
JPH03288933A true JPH03288933A (en) 1991-12-19

Family

ID=13995069

Family Applications (1)

Application Number Title Priority Date Filing Date
JP9031490A Pending JPH03288933A (en) 1990-04-06 1990-04-06 Method for controlling access to data resources

Country Status (1)

Country Link
JP (1) JPH03288933A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2010532518A (en) * 2007-06-29 2010-10-07 エミュレックス デザイン アンド マニュファクチュアリング コーポレーション Method and system for efficient queue management

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2010532518A (en) * 2007-06-29 2010-10-07 エミュレックス デザイン アンド マニュファクチュアリング コーポレーション Method and system for efficient queue management

Similar Documents

Publication Publication Date Title
US5287521A (en) Method and apparatus for releasing and obtaining shared and exclusive locks
US5598562A (en) System and method for adding new waitable object types to object oriented computer operating system
US5129084A (en) Object container transfer system and method in an object based computer operating system
US8250047B2 (en) Hybrid multi-threaded access to data structures using hazard pointers for reads and locks for updates
US5129083A (en) Conditional object creating system having different object pointers for accessing a set of data structure objects
US5057996A (en) Waitable object creation system and method in an object based computer operating system
US5136712A (en) Temporary object handling system and method in an object based computer operating system
US5608893A (en) Method for maintaining data coherency using thread activity summaries in a multicomputer system
TW498281B (en) Interface system and method for asynchronously updating a shared resource
US5187790A (en) Server impersonation of client processes in an object based computer operating system
US8473950B2 (en) Parallel nested transactions
JP2500101B2 (en) How to update the value of a shared variable
US6237019B1 (en) Method and apparatus for performing a semaphore operation
US7188344B1 (en) Architecture for a read/write thread lock
US5301337A (en) Distributed resource management system using hashing operation to direct resource request from different processors to the processor controlling the requested resource
JPH07191944A (en) System and method for prevention of deadlock in instruction to many resources by multiporcessor
US8375390B2 (en) Scheduling method and scheduling apparatus
JPH0324696B2 (en)
JPH01303527A (en) Control method for shared resources
US6662364B1 (en) System and method for reducing synchronization overhead in multithreaded code
US9891962B2 (en) Lock management system, lock management method and lock management program
JP7042105B2 (en) Program execution control method and vehicle control device
US5784623A (en) Using a parent latch that covers a plurality of child latches to track the progress of a process attempting to acquire resources
JP7346649B2 (en) Synchronous control system and method
EP4068094A1 (en) Lock-free ring buffer