教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 实用文档 >

pintos_task 1 threads

来源:网络收集 时间:2026-08-30
导读: pintos Pintos Task 1: ThreadsPaul Marinescu, Mark RutlandImperial College London February 3, 2011 Paul Marinescu, Mark Rutland (Imperial College London) intos Task 1: Threads P February 3, 2011 1/ 18 pintos Introduction GoalMake Pintos mor

pintos

Pintos Task 1: ThreadsPaul Marinescu, Mark RutlandImperial College London

February 3, 2011

Paul Marinescu, Mark Rutland (Imperial College London) intos Task 1: Threads P

February 3, 2011

1/ 18

pintos

Introduction

GoalMake Pintos more amenable for multithreading

Tasksi Non-busy sleep ii Priority scheduling iii Priority donation iv BSD-style scheduler

Paul Marinescu, Mark Rutland (Imperial College London) intos Task 1: Threads P

February 3, 2011

2/ 18

pintos

Getting Started

Where do I work?All work should be done under src/threads/& src/devices/ Compilation should occur under src/threads Any new les should be added to src/Make le.build

TestingTests can be run with: make check Single tests can be run with make build/tests/threads/test.result Some tests (mlfqs-*) take much longer to run than others

Paul Marinescu, Mark Rutland (Imperial College London) intos Task 1: Threads P

February 3, 2011

3/ 18

pintos

Important Files

Files to (possibly) modify:Most of your work will be done in the‘threads’ directory. i threads/thread.cHandles creation, modi cation, and destruction of threads Scheduling code goes here

ii threads/synch.cContains basic synchronisation constructs for multithreading

iii devices/timer.cHandles busy sleeping Calls thread tick() in threads/thread.c once every timer tick

Paul Marinescu, Mark Rutland (Imperial College London) intos Task 1: Threads P

February 3, 2011

4/ 18

pintos

Important FilesFiles with useful functionsi<debug.h>ASSERT() macro UNUSED quali er macro

ii<list.h>Generic linked-list implementation

iii<stdio.h>In-kernel implementation of printf()

iv"threads/interrupt.h"intr yield on return() makes the current thread yield after returning from an interrupt

v"threads/thread.c"thread tick() called every timer tick

Paul Marinescu, Mark Rutland (Imperial College London) intos Task 1: Threads P

February 3, 2011

5/ 18

pintos

Pintos InitialisationInitial threadInitial thread (threads/init.c: main()) is started by the boot loader Initial thread starts threads subsystem and‘promotes’ itself to a standard Pintos thread in thread init() Initialises other subsystems Parses command-line arguments Starts other threads, via thread create()

WarningThe initial thread is not created by thread create(). You may need to add initialisation code for any structures you add to thread init() also.

Paul Marinescu, Mark Rutland (Imperial College London) intos Task 1: Threads P

February 3, 2011

6/ 18

pintos

Threads in Pintos

How are threads implemented in Pintos?Threads de nes as struct thread in src/threads/thread.h Each thread is stored at the start of a 4KB page The rest of the page is used as stack space for the thread

SchedulingPreemptive Next thread chosen by next thread to run() Context switch is handled via assembly code, you should not modify it

Paul Marinescu, Mark Rutland (Imperial College London) intos Task 1: Threads P

February 3, 2011

7/ 18

pintos

Threads in Pintos

Thread statesThread

s exist in 1 of 4 possible states at any given time: THREAD RUNNING only the case for the current running thread (thread current()) THREAD READY ready to be scheduled, but not currently running (in ready list) THREAD BLOCKED unable to be run, waiting on some event (e.g. semaphore up) THREAD DYING nished with execution, waiting to be destroyed by the kernel

Paul Marinescu, Mark Rutland (Imperial College London) intos Task 1: Threads P

February 3, 2011

8/ 18

pintos

SynchronisationPintos synchronisation constructsPintos o ers several general-purpose synchronisation mechanisms (in threads/synch.c): Semaphores Locks Monitors

Interrupt handler synchronisationDisabling interrupts

WarningDo not disable interrupts unless you need exclusive access to data modi ed by an interrupt handler. Disabling interrupts is not a general-purpose synchronisation mechanism. You will lose marks for using it as such.Paul Marinescu, Mark Rutland (Imperial College London) intos Task 1: Threads P February 3, 2011 9/ 18

pintos

Project Requirements

Non-busy sleep Priority schedulingAllow processes to modify& query their priority

Priority donation for locks BSD-style schedulerFixed-point math routines

Paul Marinescu, Mark Rutland (Imperial College London) intos Task 1: Threads P

February 3, 2011

10/ 18

pintos

Non-busy sleepIdeaWhile a thread is sleeping, it must not consume any CPU.

timer sleep(int64 t ticks)Blocks the calling thread The thread must be unblocked after ticks ticks have occurred A call with a negative value for ticks should not block Allows other threads to run whilst calling thread is blocked Multiple threads may call timer sleep() simultaneously

WarningPart of your code will be in an interrupt handler. Think about shared data that must be protected from concurrent access.Paul Marinescu, Mark Rutland (Imperial College London) intos Task 1: Threads P February 3, 2011 11/ 18

pintos

Priority schedulingIdeaMake sure that at any point in time, the highest priority ready thread is running.

Yielding the processorAt certain points, another thread may have the highest priority. This could occur when: A new thread is created A thread is unblocked from a synchronisation construct A thread is woken from timer sleep If this happens the current thread should yield to it immediately

WarningSleeping threads should not be woken early, regardless of priority.Paul Marinescu, Mark Rutland (Imperial College London) intos Task …… 此处隐藏:5818字,全部文档内容请下载后查看。喜欢就下载吧 ……

pintos_task 1 threads.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/1803225.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)