2 shunfurh shunfurh 于 2017.09.18 17:52 提问

Lock Manager

Description

You are invited to be a part of the team that is developing yet another DBMS (Data Base Management System). You will be responsible for the Lock Manager.

Locks control concurrent access to data items by multiple transactions. Your DBMS is simple and uses only Shared (S) and Exclusive (X) mode locks. Each lock request contains a lock mode (S or X), a transaction identifier and a data item identifier. Multiple locks can be granted to the same data item as long as none of them conflict.

Two locks for the same data item conflict if:
they belong to different transactions, and
at least one of them is exclusive (X) mode lock.

At the earliest stages of development you are asked to write very simple lock manager that processes lock requests. The lock is granted if it does not conflict with previously granted locks for this data item. Your task is simple: locks, once granted, are never released or changed in any way. If lock request is denied due to conflict with some previously granted lock, then transaction making this request is blocked and all further requests from this transaction are ignored.
Input

The input consists of a number of lock requests, each request on a different line. Requests have the following format:

MODE TRID ITEM

Where MODE is a single capital letter S or X denoting requested lock mode. TRID and ITEM are transaction identifier and data item identifier correspondingly. Both TRID and ITEM are integers, both are greater than zero, and both consist of at most 9 decimal digits.

There are at least one and at most 10000 requests in the input file.

The last request is followed by a line consisting of a single character '#'.
Output

Your program shall sequentially process all requests from the input file. For each request you should write one line that contains the response to the request. The following responses are allowed:
GRANTED - the lock request does not conflict with any previously granted locks and is granted.
DENIED - the lock request conflicts with some previously granted lock and is denied, thus blocking the requesting transaction.
IGNORED - the transaction was blocked on some request before this one.
Responses shall appear in all capital letters exactly as shown above. An arbitrary number of blank lines can follow last response in the output file.
Sample Input

S 1 1
S 2 2
X 10 1
S 6 123456789
S 3 3
X 2 2
S 5 6
S 3 1
S 3 2
X 987654321 123456789
X 1 4
S 6 6
S 3 5
S 2 4
X 4 5
S 2 51
#
Sample Output

GRANTED
GRANTED
DENIED
GRANTED
GRANTED
GRANTED
GRANTED
GRANTED
DENIED
DENIED
GRANTED
GRANTED
IGNORED
DENIED
GRANTED
IGNORED

1个回答

caozhy
caozhy   Ds   Rxr 2017.10.02 23:47
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
【python】多进程锁multiprocess.Lock
同步的方法基本与多线程相同。   1) Lock 当多个进程需要访问共享资源的时候,Lock可以用来避免访问的冲突。 import multiprocessing import sys def worker_with(lock, f): with lock: fs = open(f,"a+") fs.write('Lock acqu
python中的multiprocessing在map函数中的加锁lock处理方式
Python多进程编程中进程池锁共享问题   python多进程编程使用进程池非常的方便管理进程,但是有时候子进程之间会抢占一些独占资源,比如consol或者比如日志文件的写入权限,这样的时候我们一般需要共享一个Lock来对独占资源加锁。lock作为一个不可直接打包的资源是没有办法作为一个参数直接给Pool的map方法里的函数传参的。为了解决这个问题,有两种解决方法,一种是使用多进程的管
hive 起步
hive中执行的SQL,会转化为一个或多个mapReduce作业并在集群上运行。   1.创建表导入单词文本文件 create table flwordcount(line string); load data inpath '/user/hadoop/input/readme.txt' overwrite into table flwordcount; 命令查看: 0: jdbc:h
org.eclipse.osgi\.manager\.fileTableLock (拒绝访问。)的最简单使用的处理办法
打开eclipse报错,让看日志,右键以管理员运行能够正常,很是郁闷;百度查了好久说是设置用户对该文件夹下的文件的操作权限,无奈设置不好用,索性右键文件夹,管理员获得所有权,等待几分钟,全部执行完成后,完美打开eclipse4.3了;
Loading.LockPersistenManager 加载资源卡顿
最近我们的游戏在加载时比较卡顿,甚至在魅族设备上直接卡到闪退,用Logcat看了一下,大概是找不到资源的问题。可是我们加载已经是异步加载了,为什么还会卡呢?我们在电脑上也没报找不到资源的错呢,为啥在魅族上会因为找不到资源闪退呢?打开Profiler一看,原来是这个地方,在Loading.LockPersistenManger卡了1000多毫秒。 网上搜了一下,原来是正式异步加载出的问题。 U
NVIDIA Jestson TX2 配置cuda以及cudnn的坑 ( JetPack-L4T 、Error: downloading update lock、TX2,TX1,TK1相关资源信息)
#PS:要转载请注明出处,本人版权所有 #PS:这个只是 《 我自己 》理解,如果和你的 #原则相冲突,请谅解,勿喷 主机信息 Linux 4.13.0-41-generic #46~16.04.1-Ubuntu SMP Thu May 3 10:06:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux JetPack-L4T 资源...
kubernetes源码阅读之controller manager启动
kubernetes源码阅读之controller manager启动
Python多进程编程-进程间协作(Queue、Lock、Semaphore、Event、Pipe)
进程与进程之间是相互独立的,互不干扰。如果多进程之间需要对同一资源操作,就需要进程间共享变量,上一篇文章介绍了进程间共享数据的三大类Value、Array、Manager,这三种类的主要区别在于管理的数据类型不同。解决了进程间共享数据的问题,又有新的问题产生,那就是当多进程同时对一个共享资源进行写操作时,容易造成数据混乱。如何解决这一问题呢?这就需要进程间相互协同。 进程间相互协同的方式有如下几
关于JetPack L4T Component Manager下载出错问题的解决办法
下载好JetPack-L4T-3.1-linux-x64.run,执行chmod +x JetPack-L4T-3.1-linux-x64.run, 在运行./JetPack-L4T-3.1-linux-x64.run,开始一路next下去,但是每每download总是卡在那里不动,最后报出error。
下载NVIDIA Codeworks卡在downloading update lock的问题
需要翻墙,比如使用shadowsocks时,在环境变量中增加http_proxy=http://127.0.0.1:1080