嵌入式导论练习题6

嵌入式导论实验报告


Introduction to Embedded Systems

Exercise 3 Resource sharing

Ex 3.1

1.Explain the difference between private, shared and exclusive resources and give an example of problems encountered in exclusive resources.

Private resources are used exclusively by one process/thread,whereas shared resources can be used by at least two possibly competing process/thread.
Simultaneous use of a resource by multiple process/threads without further countermeasures,for example,can raise inconsistencies or illegible spending on printer or monitor. Such resources are also called exclusive resources,there really should always just one process/thread exclusively take on it.

答:私有资源由一个进程/线程独占使用,而共享资源可以由至少两个可能竞争的进程/线程使用。
例如,在没有采取进一步措施的情况下,通过多个进程/线程同时使用资源可能会引起打印机或显示器上的不一致或不明确。
这样的资源分配方式也被称为独占资源,实际上应该总是只有一个进程/线程独占。只是由于虚拟化的技术,资源在肉眼不可发现的情况下供各个进程/线程轮流使用。

2.Propose three ways such that the problem occurring in Resource Sharing Problem of mutual exclusion (mutual exclusion) can be solved.

Non-preemptive tasks,interrupts disabled,static scheduling,Use of semaphores.

解决方法:非抢先任务,禁用中断,静态调度,使用信号量。

3.Explain the application of a possible solution of the previous part.

A(binary)semaphore S is a data structure that can be accessed only by the
atomic commands,wait(s),bzw. P(s) and signals (s), bzw. V(S).

Assume a process A want to enter critical section,it executes a wait(s) on the semaphore and claims the right to entry into the critical section. If the process hears that the semaphore is free,he enters the critical section and releases the semaphore with signal(s) after he left its critical section. If the call of the semaphore wait(s) is occupied by another process B,A waits until B releases the semaphore.

    (二进制)信号量S是一个数据结构,只能由原子命令P(s)V(s)操作。

    假定一个进程A想要进入临界区,它会在信号量上执行一个等待并声明进入临界区的权利。
    如果进程听到信号量是空闲的,他将进入临界区,并在离开临界区后用信号释放信号量。
    如果信号量等待的调用被另一个进程B占用,则A等待B释放信号量。
    
    信号量S是一个整数,S大于等于零是代表可供并发进程使用的资源实体数,当S小于零时则表示正在等待使用临界区的进程数。
    
    信号量操作的PV原语是:
    
    P原语操作的动作是:
    
    (1)S减1;
    
    (2)若S减1后仍大于或等于零,则进程继续执行;
    
    (3)若S减1后小于零,则该进程被阻塞后进入与该信号相对应的队列中,然后转进程调度。
    
    V原语操作的动作是:
    
    (1)S加1;
    
    (2)若相加结果大于零,则进程继续执行;
    
    (3)若相加结果小于或等于零,则从该信号的等待队列中唤醒一等待进程,然后再返回原进程继续执行或转进程调度。
    
    PV操作对于每一个进程来说,都只能进行一次,而且必须成对使用。在PV原语执行期间不允许有中断的发生。
    
    信号量机制分 整型信号量机制、记录型信号量机制、and型信号量机制、信号量集。
    
    整型信号量是一种最简单的信号量,主要用于解决并发程序互斥访问临界资源问题。

Ex 3.2

4.In the lecture you learned about the Priority Inheritance Protocol (PIP). Does the PIP solve the problem of deadlocks? Give a brief explanation for your response.

No, the PIP does not prevent deadlocks.

答:不能,PIP不能防止死锁。

PIP优先级继承协议(Priority Inheritance Protocol,
PIP)的基本思想是当更高优先级的进程Ji被进程Jk阻塞时,Jk暂时继承Ji的优先级,这将防止中间优先级的进程抢占进程Jk使高优先级进程Ji的阻塞时间延长。

PIP优先级继承协议中的死锁问题:

低优先级作业Jl获取信号量S1进入临界区Z1,在执行过程中高优先级Jh抢占Jl并获取信号量S2进入临界区Z2,在Z2中Jh申请S1被Jl阻塞,Jl继承Jh优先级继续执行Z1,此时Jl需要获取S2,死锁产生。

5.Given are the four tasks J1, J2, J3 and J4. The table below contains
information on their arrival times, deadlines, their execution time and priorities. The tasks with fixed priorities should be handled by a fixed priority scheduling processor as far as possible within their deadlines.

The drawings in the last row of the table provide information about the
sequence of individual tasks. Each task contains one or more critical sections, in which the system accesses the two exclusive resources A and B, respectively. In the drawings, each block has one unit of length and non-critical sections are shaded. The critical sections are marked with the corresponding letters A and B. For example, the seven time units long task J4 contains two critical sections, the five time periods long section A and the three time units long section B. A and B are nested here, i.e. during the periods 3-5 J4 must have access to both resource A and resource B.

ex3.jpg

Task:

Now create a scheduling with the Priority Inheritance Protocol and fill out the chart prepared below. Highlight the critical Portions of the tasks with the letters A and B as specified in the last line of the table . Please also
characterized p4 which is the active priority of Task J4 in the

given diagram. Note: Pay close attention to the priorities of the individual
tasks!

ex3_1.jpg
ex3_1fill.jpg

6.Are all deadlines satisfied through the application of the PIP? If not, how big is the maximum delay (maximum lateness) in units

of time?

No,J2 violated its deadline by two time units.

答:不满足,J2违反两个时间单位的最后期限。
  1. Is there a schedule for the tasks specified J1 to J4 that meets all
    deadlines? What changes should be made to the priority? If there is a correct schedule, please show it in the graph provided below. Otherwise, explain why there can be no correct schedule.

Yes,there is a flow chart such that all deadlines can be met. However,one have to change the priority of at least one task. If PIP is to meet all
deadlines,for example,the priority order J4>J1>J2>J3 is a good choice.

是的,有一个流程图,可以满足所有的最后期限。
但是,必须改变至少一个任务的优先级。
如果PIP要满足所有最后期限,例如,优先顺序J4\> J1\> J2\> J3是一个不错的选择。
ex3_2.jpg
ex3_2fill.jpg
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,686评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,668评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,160评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,736评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,847评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,043评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,129评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,872评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,318评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,645评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,777评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,470评论 4 333
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,126评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,861评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,095评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,589评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,687评论 2 351

推荐阅读更多精彩内容