首页 > 编程语言 >CSSE7610互斥算法分析

CSSE7610互斥算法分析

时间:2023-09-01 18:22:05浏览次数:39  
标签:last 算法 互斥 CSSE7610 critical marks cards your card


Assignment 1: Mutual exclusion CSSE7610
Answer questions 1 to 3 below. This assignment is worth 25% of your final mark. It is to
be completed individually, and you are required to read and understand the School Statement on
Misconduct, available on the School’s website at: https://eecs.uq.edu.au/current-students/
guidelines-and-policies-students/student-conduct
Due date and time: Thursday 7 September, 3pm
Peterson’s mutual exclusion algorithm is based on Dekker’s algorithm but is more concise because
it collapses two await statements into one with a compound condition.
Peterson’s algorithm
boolean wantp ← false, wantq ← false
integer last ← 1
p q
loop forever loop forever
p1: non-critical section q1: non-critical section
p2: wantp ← true q2: wantq ← true
p3: last ← 1 q3: last ← 2
p4: await wantq = false or q4: await wantp = false or
last = 2 last = 1
p5: critical section q5: critical section
p6: wantp ← false q6: wantq ← false
1. Prove the correctness of Peterson’s algorithm using deductive techniques. Given the following
invariants similar to those of Dekker’s algorithm
(a) (last = 1) ∨ (last = 2)
(b) p3..6 ⇔ wantp
(c) q3..6 ⇔ wantq
first show that
(p4 ∧ q5) ⇒ (wantq ∧ last = 1),
(p5 ∧ q4) ⇒ (wantp ∧ last = 2)
are also invariants, and then use them to prove mutual exclusion holds. Then state the
condition for freedom from starvation for process p and provide a proof that it holds.
Deliverable: A file peterson.pdf containing the correctness arguments, and your name and
student number.
2. (a) Write a Promela specification for a modified version of Peterson’s algorithm that does
not have more than one critical reference in any atomic statement.
(b) Use Spin to prove that the algorithm is still correct: use an assertion to prove mutual
exclusion, and an LTL property to prove freedom from starvation.
Deliverables: A file peterson.pml containing the Promela specification and including comments detailing how you carried out the proofs and stating any LTL properties required.
The pml file must include your name and student number (as a comment).
1
3. Speed is a card game where the players simultaneously try to get rid of all their cards.
In this version of the game, we have 2 players and use a pack of 60 cards. Each card has
between 1 and 5 motifs of a particular shape and colour on it. For example, a card may
have 4 green diamonds, or it may have 5 blue circles, or it may have 1 red square. We will
assume there are 6 different shapes and 6 different colours, and that the pack has a random
selection of 60 such cards which may contain duplicate cards.
Each player is dealt a pile of 29 cards and the remaining two cards are placed face up in front
of the players. The players pick up the top 3 cards from their pile and must simultaneously
try to place them on one of the cards in the centre by either matching the colour, shape or
number (of shapes). For example, a player may put a card with 4 red circles on a card with
2 red squares (colour is matched), or a card with 3 green diamonds on a card with 3 blue
circles (number is matched). When a player places a card in the centre, it replaces the one
it is on top of as one of the two cards that must be matched.
A player can pick up the next card from their pile whenever they have less than 3 cards in
their hand. The winner is the first player to put down all 29 of their cards. If both players
reach a point where they are not able to put down any more cards, the game is a draw.
Write a Java program to simulate the game of Speed. Each player must be implemented
as a thread and Peterson’s algorithm must be used where mutual exclusion is required.
(You should not use locks, semaphores, or the synchronized or wait/notify capabilities
of Java objects in this assignment.1
) The program should use the provided class Card.java
for modelling cards, and produce output by calling the appropriate methods of the provided
class Event.java. For testing purposes, it is a requirement that you call the Event class every
time one of the events occurs. It is also important that you do not modify either of the
provided classes.
The critical sections must include the minimal number of statements to ensure the correct
behaviour. For example, a player thread should not search for a matching card while in
the critical section, although it may need to check that a previously chosen card is still a
valid choice. As well as global variables representing the cards in the centre of play, you
may require additional global variables, e.g. to allow the threads to determine a draw has
occurred.
Deliverables: A zip file containing the file Speed.java (which includes your main method)
along with all supporting source (.java) files (apart from Card and Event), and a file
readme.txt describing (in a few paragraphs) the approach you have taken to coding the
program and providing a list of all your classes and their roles. All Java files should be
well-documented and in particular the critical section code and code for detecting draws
should be well explained. All files should also contain your name and student number (as a
comment).
To assist with my testing of your Java code. Please do not make your submitted files
dependent on being in a particular package. That is, remove any lines:
package packageName;
1Of course, you would use such constructs in practice, and you will do so in Assignment 2. The intention of this
assignment is to give you experience with mutual exclusion algorithms.
2
Marking criteria
Marks will be given for the correctness and readability of answers to questions 1 to 3 as follows.
Question 1 (10 marks)
ˆ Proof of invariants (4 marks)
ˆ Proof of mutual exclusion using invariants (2 marks)
ˆ Proof of starvation freedom (4 marks)
Question 2 (5 marks)
ˆ Promela specification of algorithm (3 marks)
ˆ Proof method for mutual exclusion (1 mark)
ˆ Proof method for starvation freedom (1 mark)
Question 3 (10 marks)
ˆ readme file (1 mark)
ˆ Java thread class modelling players (5 marks)
ˆ Program producing correct behaviour for a winning game (2 marks)
ˆ Program producing correct behaviour for a draw (2 marks)

标签:last,算法,互斥,CSSE7610,critical,marks,cards,your,card
From: https://www.cnblogs.com/goodnewss/p/17672641.html

相关文章

  • Lnton 羚通智能分析算法智慧停车检测算法
    智慧停车算法是指利用各种传感器技术和数据分析方法,通过智能化的方式管理和优化停车场资源利用的算法。近年来,为了扩充停车位的数量,缓解停车压力,路边停车的方式开始逐步推广。对于路边车位的管理,基于视觉的方案与人工、咪表、地磁等方案相比,其成本更低且易于部署,具有较大的研究和推......
  • Java 迪杰斯特拉 算法实现
    在这里记录下自己写的迪杰斯特拉代码。思路本质是贪心算法:开始时设定两个集合:S,T;S存入已经遍历的点,T存所有未遍历的点;首先将起点放入S中,更新T中所有节点的权重(和起点联通的节点更新权重,其他节点权重设为无穷大);在T中寻找权重最低的点(假设是M点),将M点放入S中,同时更新T里所有节......
  • Lnton羚通视频分析算法平台OpenCV-Python直方图反向投影教程
    OpenCVPython直方图反向投影用于图像分割和查找感兴趣目标。简单的说,会创建一个与输入图像同样大小的图像(单通道),每个像素对应像素属于目标的概率。更简单的说就是,输出图像在感兴趣的目标处更白。常常与camshift算法一起使用,用于目标跟踪(查找目标)如何使用呢?创建一个图像的直方......
  • Lnton羚通视频分析算法平台OpenCV-Python教程 图像变换(频域变换)
     频域变换是一种将信号从时间域表示转换为频率域表示的方法。它可以帮助我们理解信号的频率成分以及进行信号处理和分析。常见的频域变换方法包括傅里叶变换(FourierTransform)和离散傅里叶变换(DiscreteFourierTransform,DFT)。以下是它们的简要介绍:傅里叶变换(FourierTransform):......
  • 《落实算法安全主体责任基本情况》范文,修改主体即可提交
      在数字化时代,算法已经成为了商业竞争和创新的关键要素。然而,算法的广泛应用也引发了对其安全性和合规性的关切。《落实算法安全主体责任基本情况》作为算法备案过程中的一环,具有极高的专业性,需要企业全面考虑算法的隐私保护、数据合规、风险预防等一系列关键问题。正因如......
  • Lnton羚通算法算力云平台【PyTorch】教程:torch.nn.Mish
    torch.nn.Mish是PyTorch中的一个激活函数类,它实现了Mish激活函数。Mish是一种近年来提出的激活函数,它在激活函数的设计中引入了自适应斜率。Mish函数的定义如下:Mish(x)=x*tanh(softplus(x))其中softplus(x)是软正值函数,定义为softplus(x)=log(1+exp(x))。Mish函......
  • mp之id雪花算法及其他主键策略
    默认主键策略为ASSIGN_ID(全局唯一id)AUTO为自增id,需要在数据库中设置主键自增NONE为不设置主键策略INPUT将主键设置为手动输入ASSIGN_UUID也是全局唯一id 实现步骤:在实体类中加入注解@TableId(type=IDType.AUTO)即可 ......
  • 贪心算法-Huffman树
    贪心算法-Huffman树1.哈并果子问题的概述及案例https://www.acwing.com/problem/content/150/上图为本问题的案例。实际上,本题就是霍夫曼树的应用。关于霍夫曼树的定义,这里就不再赘述。根据上图,实际上这道题就是在询问:将所有的果子堆进行合并,构造成一......
  • [6]-代码随想录算法训练营-dat7-哈希表-part2
    代码随想录算法训练营第七天|哈希表-part21.LeetCode454.四数相加II题目https://leetcode.cn/problems/4sum-ii/submissions/思路无刷随想录后想法将四数相加转化为两数之和借用unordered_map,利用两数之和思想解决本问题实现困难代码尚模糊,不过整个......
  • KMP算法--解决字符串匹配问题--模式串是否在文本串出现过
    KMP算法--解决字符串匹配问题--模式串是否在文本串出现过*利用之前判断过的信息,通过next数组保存最长公共子序列的长度*搜索词/模式串移动的位数=已匹配的字符数-对应的部分匹配值在韩的例子里ABCDABD初次匹配匹配了ABCDAB6位,对应2,所以移动6-2=4位e.g.文本串aabaabaaf......