由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - careercup 150 deadlock 一题
相关主题
问一个CareerCup上的题怎样 avoid deadlock ??
上个Yahoo电面面经, 给恶心坏了。。careercup上infinite counter的题目
求助:非cs ms onsite 怎么准备ArrayList是Java里的吧,C++下面怎么办?
贡献邮件面试题(Web Development)请教刷题
最讨厌的就是找到工作了, 然后来教育我们没找到工作的linux下, 一个thread 正在写文件,如果另一个thread试图去删去 (转载)
请教个题目有人愿意合买careercup那本书吗?
面试中遇上同一类的问题不会,请问这些都是哪方面的内容?微软面试题
请教CareerCup中的ROBOT MATRIX PATH那道题CareerCup 13.9的solution有memory leak
相关话题的讨论汇总
话题: resource话题: arraylist话题: count话题: res话题: deadlock
进入JobHunting版参与讨论
1 (共1页)
I******y
发帖数: 176
1
design a class which provides a lock only if there are no possible deadlocks
解答并没有给出到底什么时候可以acquire lock阿.这个canAcquireResource具体怎么
实现呢
For our solution, we implement a wait / die deadlock prevention scheme.
1 class MyThread extends Thread {
2 long time;
3 ArrayList res = new ArrayList();
4 public ArrayList getRes() { return res; }
5
6 public void run() {
7 /*run infinitely*/
8 time = System.currentTimeMillis();
9 int count = 0;
10 while (true) {
11 if (count < 4) {
12 if (Question.canAcquireResource(this,
13 Question.r[count])) {
14 res.add(Question.r[count]);
15 count++;
16 System.out.println(“Resource: [“ +
17 Question.r[count - 1].getId() + “] acquired by
18 thread: [“ + this.getName() + “]”);
19 try {
20 sleep(1000);
21 } catch (InterruptedException e) {
22 e.printStackTrace();
23 }
24 }
25 }
26 else {
27 this.stop();
28 }
29 }
30 }
31
32 public long getTime() { return time; }
33 public void setRes(ArrayList res) { this.res = res; }
34 MyThread(String name) {
35 super(name);
36 }
37 }
1 (共1页)
进入JobHunting版参与讨论
相关主题
CareerCup 13.9的solution有memory leak最讨厌的就是找到工作了, 然后来教育我们没找到工作的
一个老算法题【update】请教个题目
弱问一道G题面试中遇上同一类的问题不会,请问这些都是哪方面的内容?
最郁闷的facebook面试+面经。请教CareerCup中的ROBOT MATRIX PATH那道题
问一个CareerCup上的题怎样 avoid deadlock ??
上个Yahoo电面面经, 给恶心坏了。。careercup上infinite counter的题目
求助:非cs ms onsite 怎么准备ArrayList是Java里的吧,C++下面怎么办?
贡献邮件面试题(Web Development)请教刷题
相关话题的讨论汇总
话题: resource话题: arraylist话题: count话题: res话题: deadlock