摘要: 忙等待就不说了。参考nachos虚拟操作系统,给出锁的实现:void Lock::Acquire(){ IntStatus oldLevel = interrupt->SetLevel(IntOff); // disable interrupts while (value == BUSY) { // Here we must use while. queue->Append((void *)currentThread); // put thread into the waitqueue. currentThread->Sleep(); } ... 阅读全文
posted @ 2013-09-03 20:03 xmuliushuo 阅读(303) 评论(0) 推荐(0)
摘要: 原文地址:http://blog.sina.com.cn/s/blog_4d3a41f401011bxd.html给定一个字符串的集合,格式如:{aaa bbb ccc}, {bbb ddd},{eee fff},{ggg},{ddd hhh}要求将其中交集不为空的集合合并,要求合并完成后的集合之间无交集,例如上例应输出{aaa bbb ccc ddd hhh},{eee fff}, {ggg}。(1)请描述你解决这个问题的思路;(2)请给出主要的处理流程,算法,以及算法的复杂度(3)请描述可能的改进。集合使用hash_set来表示,这样合并时间复杂度比较低。1. 给每个集合编号为0,1,2, 阅读全文
posted @ 2013-09-03 17:25 xmuliushuo 阅读(574) 评论(0) 推荐(0)