《Cracking the Coding Interview》——第16章:线程与锁——题目4
2014-04-27 20:06
题目:设计一个类,只有在不产生死锁的时候才分配资源。
解法:不太清楚这个题是要分配何种资源,以何种形式?所以没能动手写个可运行的代码,只是闲扯了几句理论分析。
代码:
// 16.4 Design a class which provides a lock only if no deadlock would take place.
. The class will maintain a list of all locks that would be requested by different processes.
private Vector<Lock> locks;
. The class will have a real-time record of which processes are using which locks. Mapping the process ID with a queue recording the locks it is using.
private HashMap<int, Queue<Lock> > lockOccupations;
. The class will perform deadlock detection before assigning a certain lock to a certain process.
private bool deadLockDetection(int processID, int lockID);
. The class will provide a public method to assign a lock to a process.
public bool getLock(int processID, int lockID); About dead lock detection:
Generally, dead lock detection is about detecting a loop in a directed graph. Using DFS will be a solution.
《Cracking the Coding Interview》——第16章:线程与锁——题目4的更多相关文章
- Cracking the coding interview 第一章问题及解答
Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...
- 《Cracking the Coding Interview》读书笔记
<Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...
- Cracking the coding interview
写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...
- Cracking the Coding Interview(Stacks and Queues)
Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...
- Cracking the coding interview目录及资料收集
前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...
- Cracking the Coding Interview(Trees and Graphs)
Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...
- 《Cracking the Coding Interview》——第16章:线程与锁——题目6
2014-04-27 20:25 题目:关于java中标有synchronized的成员方法? 解法:这代表同一个对象实例的synchronized方法不能被多个线程同时调用.注意有这么多个地方都加粗 ...
- 《Cracking the Coding Interview》——第16章:线程与锁——题目5
2014-04-27 20:16 题目:假设一个类Foo有三个公有的成员方法first().second().third().请用锁的方法来控制调用行为,使得他们的执行循序总是遵从first.seco ...
- 《Cracking the Coding Interview》——第16章:线程与锁——题目2
2014-04-27 19:14 题目:如何测量上下文切换的时间? 解法:首先,上下文切换是什么,一搜就知道.对于这么一个极短的时间,要测量的话,可以通过放大N倍的方法.比如:有A和B两件事,并且经常 ...
- 《Cracking the Coding Interview》——第16章:线程与锁——题目1
2014-04-27 19:09 题目:线程和进程有什么区别? 解法:理论题,操作系统教材上应该有很详细的解释.我回忆了一下,写了如下几点. 代码: // 16.1 What is the diffe ...
随机推荐
- WannaCry勒索病毒卷土重来:日本本田工厂被迫关闭
6月22日消息,前阵子WannaCry勒索病毒席卷全球,世界各地网络遭到攻击.日前,偃旗息鼓了一阵的WannaCry勒索病毒又重回人们视线,迫使一家汽车厂在日本关闭. 路透社报道,本田Sayama工厂 ...
- Verilog八线 - 三线优先编码器设计(74LS148)
百度百科_74LS148 if语句法 //8线-3线优先编码器设计(74LS148) // //EI | A7 A6 A5 A4 A3 A2 A1 A0 | Y2 Y1 Y0 GS EO //0 | ...
- 1 - python3基础语法
编码 默认情况下,Python 3 源码文件以 UTF-8 编码.当然你也可以为源码文件指定不同的编码: # _*_ coding:utf-8 _*_ 保留字 Python的标准库提供了一个keywo ...
- April 20 2017 Week 16 Thursday
We are all in the gutter, but some of us are looking at the stars. 我们都生活在阴沟里,但仍有人仰望星空. In the past m ...
- 初学React:JSX语法
这是本人初学React做的学习笔记;讲的不是很深,只算是简单的进行介绍. 这是一个小系列.都是在同一个模板中搭建的,但是代码是不能正常执行的. >>第一个组件.js 'use strick ...
- 进程管理—进程描述符(task_struct)
http://blog.csdn.net/qq_26768741/article/details/54348586 当把一个程序加载到内存当中,此时,这个时候就有了进程,关于进程,有一个相关的叫做进程 ...
- 数长方形有多少个?POJ(1693)
题目链接:http://poj.org/problem?id=1693 解题报告: 随机选两根横的,再找一下与这两根横线相交的竖线有多少根,m,那么就有(m-1)*m/2个长方形. #include ...
- 【转】如何手动添加Android Dependencies包
在ADT16 之前可以在工程里面做关联,eclipse会在工程上自动添加ReferenceLibrary.新版本的ADT修改了第三方jar的导入方式,只需要在工程目录下新建libs文件夹,注意是lib ...
- Compass Card Sales(模拟)
Compass Card Sales 时间限制: 3 Sec 内存限制: 128 MB提交: 35 解决: 13[提交] [状态] [讨论版] [命题人:admin] 题目描述 Katla has ...
- wcf 的 知识点
1. wcf 的9种 协议