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的更多相关文章

  1. Cracking the coding interview 第一章问题及解答

    Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...

  2. 《Cracking the Coding Interview》读书笔记

    <Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...

  3. Cracking the coding interview

    写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...

  4. 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 ...

  5. Cracking the coding interview目录及资料收集

    前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...

  6. Cracking the Coding Interview(Trees and Graphs)

    Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...

  7. 《Cracking the Coding Interview》——第16章:线程与锁——题目6

    2014-04-27 20:25 题目:关于java中标有synchronized的成员方法? 解法:这代表同一个对象实例的synchronized方法不能被多个线程同时调用.注意有这么多个地方都加粗 ...

  8. 《Cracking the Coding Interview》——第16章:线程与锁——题目5

    2014-04-27 20:16 题目:假设一个类Foo有三个公有的成员方法first().second().third().请用锁的方法来控制调用行为,使得他们的执行循序总是遵从first.seco ...

  9. 《Cracking the Coding Interview》——第16章:线程与锁——题目2

    2014-04-27 19:14 题目:如何测量上下文切换的时间? 解法:首先,上下文切换是什么,一搜就知道.对于这么一个极短的时间,要测量的话,可以通过放大N倍的方法.比如:有A和B两件事,并且经常 ...

  10. 《Cracking the Coding Interview》——第16章:线程与锁——题目1

    2014-04-27 19:09 题目:线程和进程有什么区别? 解法:理论题,操作系统教材上应该有很详细的解释.我回忆了一下,写了如下几点. 代码: // 16.1 What is the diffe ...

随机推荐

  1. 16 Javascript

    网上找网页模板: 1.HTML模板 2.BootStrap 前面内容总结 HTML 标签:块级,行内 CSS 后台管理布局 position: fixed  ---永远固定在窗口的某个位置 relat ...

  2. 数据结构与算法分析java——线性表2(ArrarList )

    ArrayList ArrayList 是一个数组队列,相当于 动态数组.与Java中的数组相比,它的容量能动态增长.它继承于AbstractList,实现了List, RandomAccess, C ...

  3. Linux MySQL单实例源码编译安装5.5.32

    cmake软件 tar -zxvf cmake-2.8.8.tar.gz cd cmake-2.8.8 ./bootstrap make make install cd ../   依赖包 yum i ...

  4. spring教程(一):简单实现(转)

    转:https://www.cnblogs.com/Lemon-i/p/8398263.html  一.概念介绍 1. 一站式框架:管理项目中的对象.spring框架性质是容器(对象容器) 2. 核心 ...

  5. 如何迅速掌握并提高linux运维技能(收藏文)

    如何迅速掌握并提高linux运维技能   文章来源于南非蚂蚁   之前曾经写过一篇如何学习Linux的文章,得到了很多反馈,大家都在分享自己的学习经验和体会,并且也提出了不少意见和建议.学习这个事情其 ...

  6. H3C S2100配置管理vlan与交换机管理IP

    管理 VLAN 简介:S2100系列以太网交换机任何时刻只能有一个VLAN对应的VLAN接口可以配置IP地址,该 VLAN 即为管理 VLAN.如果要对以太网交换机进行远程管理,必须配置交换机管理 V ...

  7. TypeScript学习-TypeScript环境配置

    http://blog.csdn.net/shi_weihappy/article/details/49332091

  8. Could not autowire. No beans of 'TbAssetsMapper' type found. less... (Ctrl+F1) Inspection info:Checks autowiring problems in a bean class.

    报错:Could not autowire. No beans of 'TbAssetsMapper' type found. less... (Ctrl+F1) Inspection info:Ch ...

  9. 统计文件中的URL

    1. 题目: 一个文本文件中每一行中有一个URL,最多一万行,统计每一个URL的次数,输出到另外一个文件中,每一行前面是URL,后面是个数. 2.代码: package test; import ja ...

  10. LinkedHashMap使用心得

    基本概念:https://www.cnblogs.com/xiaoxi/p/6170590.html 遇到问题: 1.构造方法 public static LinkedHashMap<Strin ...