7.3.1 Suzuki–Kasami Algorithm This algorithm is defined for a completely connected network of processes. It assumes that initially an arbitrary process has the token. A process i that does not have the token but wants to enter its CS broadcasts a request (i, num), where num is sequence number of that request. The algorithm guarantees that eventually process i receives the token. Every process i maintains an array req[0.. n − 1] of integers, where req[j] designates the sequence number of the latest request received from process j. Note that although every process receives a request, only one process (which currently has the token) can grant the token. As a result, some pending requests become stale or outdated. An important issue in this algorithm is to identify and discard these stale requests. To accomplish this, each process uses the following two additional data structures that are passed on with the token by its current holder: • An array last[0.. n − 1] of integers, where last[k] = r implies that during its last visit to its CS, process k has completed its rth trip • A queue Q containing the identifiers of processes with pending requests When a process i receives a request with a sequence number num from process k, it updates req[k] to max(req[k], num), so that req[k] now represents the most recent request from process k. A process holding the token must guarantee (before passing it to another process) that its Q contains the most recent requests. To satisfy this requirement, when a process i receives a token from another process, it executes the following steps: • It copies its num into last[i]. • For each process k, process i retains process k’s name in its local queue Q only if 1 + last[k] = req[k] (this establishes that the request from process k is a recent one). • Process i completes the execution of its CS codes. • If Q is nonempty, then it forwards the token to the process at the head of Q after deleting its entry. To enter the CS, a process sends (n − 1) requests and receives one message containing the token. The total number of messages required to complete one visit to its CS is thus (n − 1) + 1 = n. Readers are referred to [SK85] for a proof of this algorithm理解Suzuki-Kasami算法,并回答如下问题: 算法是如何辨别和丢弃过时的请求的,或者说为什么要求1 + last[k] = req[k]?
时间: 2024-02-14 12:09:41 浏览: 221
每个进程都维护了一个req数组,表示从其他进程发送来的请求的最新编号。当一个进程收到来自进程k的编号为num的请求时,它会更新req[k]为max(req[k], num),以表示进程k的最新请求。但是,由于只有一个进程拥有令牌,因此某些请求可能已经过时或过期。为了识别和丢弃这些过时的请求,每个进程使用两个附加的数据结构,即last数组和队列Q。当一个进程获得令牌时,它需要保证其Q包含最新的请求。因此,为了满足这个要求,当一个进程i从另一个进程收到令牌时,它会执行以下步骤:
- 将自己的编号num复制到last[i]中。
- 对于每个进程k,只有当1+last[k]=req[k]时,进程i才会在本地队列Q中保留进程k的名称(这表明进程k的请求是最新的)。
- 进程i完成其临界区代码的执行。
- 如果Q非空,则删除其条目后将令牌转发给Q头部的进程。
因此,要求1 + last[k] = req[k]是为了确保只有最新的请求被保留在队列Q中,过时的请求将被丢弃。
相关问题
The project is using an incompatible version (AGP 7.3.1) of the Android Gradle plugin. Latest supported version is AGP 7.2.2
为什么项目正在使用一个不兼容的版本(AGP 7.3.1)的Android Gradle插件?支持的最新版本是AGP 7.2.2。这个问题可能是由于项目中使用的一些库或组件需要7.3.1版本的AGP,但您的Gradle版本并不支持它。为了解决这个问题,您可以尝试升级Gradle或查找与7.2.2版本的AGP兼容的组件。
The project is using an incompatible version (AGP 7.4.2) of the Android Gradle plugin. Latest supported version is AGP 7.3.1
这个问题的意思是项目使用了不兼容的Android Gradle插件版本(AGP 7.4.2),而最新支持的版本是AGP 7.3.1。Android Gradle插件是Android Studio和Gradle构建系统之间的桥梁,它允许您构建和打包Android应用程序。如果你的项目使用了不兼容的版本,可能会导致构建失败或其他问题。
解决这个问题的方法是将Android Gradle插件版本降级到支持的版本(AGP 7.3.1)。您可以在项目根目录下的build.gradle文件中找到以下代码块:
```
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
}
```
将其修改为:
```
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
}
```
然后重新构建您的项目即可。
阅读全文