提纲 1 2 OS Examples for 3

Similar documents
第7章-并行计算.ppt

ebook

Microsoft Word - (web)_F.1_Notes_&_Application_Form(Chi)(non-SPCCPS)_16-17.doc

Chapter 9: Objects and Classes

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

穨series019-IA.PDF

IP505SM_manual_cn.doc

Oracle 4

A Preliminary Implementation of Linux Kernel Virus and Process Hiding

提纲 Classical Problems of Synchronization 1 Classical Problems of Synchronization 2 3 4

詞 彙 表 編 號 詞 彙 描 述 1 預 約 人 資 料 中 文 姓 名 英 文 姓 名 身 份 證 字 號 預 約 人 電 話 性 別 2 付 款 資 料 信 用 卡 別 信 用 卡 號 信 用 卡 有 效 日 期 3 住 房 條 件 入 住 日 期 退 房 日 期 人 數 房 間 數 量 入

Microsoft PowerPoint - os_4.ppt

Microsoft PowerPoint SSBSE .ppt [Modo de Compatibilidade]

ch_code_infoaccess

恩 典 课 堂 教 学 概 览 课 堂 环 节 持 续 时 间 活 动 所 需 材 料 欢 迎 在 门 口 欢 迎 孩 子, 聆 听 他 们 分 享 本 周 开 心 或 烦 恼 的 事 无 预 备 活 动 <10 分 钟 A 十 诫 石 板 B 我 是 谁? 粘 土 牙 签 一 些 名 人 的 照

软件测试(TA07)第一学期考试

The Development of Color Constancy and Calibration System

I

Java

14 建筑环境设计模拟分析软件DeST--辅助商业建筑设计应用实例.doc

第3章.doc

OSI OSI 15% 20% OSI OSI ISO International Standard Organization 1984 OSI Open-data System Interface Reference Model OSI OSI OSI OSI ISO Prototype Prot

C 1

2 2 3 DLight CPU I/O DLight Oracle Solaris (DTrace) C/C++ Solaris DLight DTrace DLight DLight DLight C C++ Fortran CPU I/O DLight AM

國立中山大學學位論文典藏.PDF

Microsoft Word mpc-min-chi.doc

( ) 1

穨cwht.PDF

900502_Oasis.indb

bnb.PDF

untitled

Microsoft Word - om388-rnt _excl Items 16 & 38_ _final_for uploading_.doc

% 25% (i) 95% 96,290,900 (ii) 99.9% 17,196,000 (iii) 99.9% 89,663,100 2

¨Æ·~½g¡ã¾·~¤ÀÃþ

Microsoft Word _4

郑州大学(下).doc

厨房小知识(六)

广 东 纺 织 职 业 技 术 学 院 发 展 党 员 公 示 制 实 施 办 法 关 于 推 荐 优 秀 团 员 作 为 党 的 发 展 对 象 工 作 的 意 见 后 勤 管 理 工 作 广 东 纺 织 职 业 技 术 学 院 新 引 进 教 职 工 周 转 房 管 理


游戏攻略大全(五十).doc

金融英语证书考试大纲


健康知识(二)

中南财经大学(二).doc

广西大学(一).doc

根据学校教学工作安排,2011年9月19日正式开课,也是我校迁址蓬莱的第一学期开学

山东大学(一).doc

2

主 编 : 杨 林 副 主 编 : 张 新 民 邹 兰 曹 纯 纯 周 秋 婷 李 雅 清 黄 囡 囡 评 审 顾 问 : 杨 林 张 新 民 评 审 : 张 新 民 邹 兰 曹 纯 纯 周 秋 婷 李 雅 清 黄 囡 囡 李 忆 萍 徐 如 雪 文 字 编 辑 : 曹 纯 纯 邹 兰 李 雅 清

最新文物管理执法全书(十四).doc

园林常识(二).doc

前 言 二 一 六 年 四 月 四 日, 兒 童 節, 誕 生 了 一 件 美 事 : 中 國 作 家 曹 文 軒 在 意 大 利 博 洛 尼 亞 國 際 童 書 展 榮 獲 國 際 安 徒 生 文 學 獎, 是 該 獎 創 設 六 十 年 來, 第 一 位 摘 桂 的 中 國 作 家, 意 義 重

湖 南 科 技 大 学

上海外国语大学(二).doc

2009 陳 敦 德

切 实 加 强 职 业 院 校 学 生 实 践 能 力 和 职 业 技 能 的 培 养 周 济 在 职 业 教 育 实 训 基 地 建 设 工 作 会 议 上 的 讲 话 深 化 教 育 教 学 改 革 推 进 体 制 机 制 创 新 全 面 提 高 高 等 职 业 教 育 质 量 在

鸽子(三)

兽药基础知识(四)

园林植物卷(十).doc

园林植物卷(十七).doc

临床手术应用(三)

家装知识(二十)

医疗知识小百科

家庭万事通(一)

家装知识(三)

园林绿化(一)

园林植物卷(十五).doc

最新监察执法全书(一百五十).doc

兽药基础知识(三)

奥运档案(四).doc

最新监察执法全书(五十).doc

最新执法工作手册(三百八十四)

中华美食大全4

动物杂谈_二_.doc

抗非典英雄赞歌(三)

新时期共青团工作实务全书(三十五)

经济法法律法规第十九卷

游戏攻略大全(五十九).doc

火灾安全实例

兽药基础知识(七)

实用玉米技术(二)

中国政法大学(一).doc

水产知识(一)

招行2002年半年度报告全文.PDF

(Microsoft Word - outline for Genesis 9\243\2721\243\25529.doc)

穨Shuk-final.PDF

2

游戏攻略大全(五十二).doc

游戏攻略大全(五十一).doc

公務員懲戒法實務及新制

大小通吃-糖尿病


98825 (Project Sunshine) Chi_TC_.indb

高雄市左營國民小學八十九學年度第一學期一年級總體課程教學進度表

IP TCP/IP PC OS µclinux MPEG4 Blackfin DSP MPEG4 IP UDP Winsock I/O DirectShow Filter DirectShow MPEG4 µclinux TCP/IP IP COM, DirectShow I

C++ 程式設計

Microsoft PowerPoint - L17_Inheritance_v4.pptx

SP_ SP_03 JAVA...6 SP_10 SQL...8 SP_ SP_ SP_ SP_ SP_ SP_ SP_ SP_04.NET...33 SP_02 C...37 SP_05

投影片 1

<4D F736F F F696E74202D20C8EDBCFEBCDCB9B9CAA6D1D0D0DEBDB2D7F92E707074>

Transcription:

第 4 章 Threads2( 线程 2) 中国科学技术大学计算机学院 October 28, 2009

提纲 1 2 OS Examples for 3

Outline 1 2 OS Examples for 3

Windows XP Threads I An Windows XP application runs as a seperate process, and each process may contain one or more threads Implements the one-to-one mapping each user-level thread maps to an assotiated kernel thread any thread belonging to a process can access the address space of the process Each thread contains A thread id Register set Separate user and kernel stacks Private data storage area The register set, stacks, and private storage area are known as the context of the threads

Windows XP Threads II The primary data structures of a thread include: ETHREAD (executive thread block) KTHREAD (kernel thread block) TEB (thread environment block)

Windows XP Threads III

Linux Threads Linux refers to them as tasks rather than threads Thread creation is done through clone() system call clone() allows a child task to share the address space of the parent task (process) clone() VS fork()

Java Threads Java 在语言级提供线程创建和管理支持功能 Java threads are managed by the JVM, not user-level library or kernel Java threads may be created by: Extending Thread class Implementing the Runnable interface Java

Thread States

Outline OS Examples for 1 2 OS Examples for 3

OS Examples for user-level thread : kernel-level thread (or LWP) Local Scheduling How the threads library decides which thread to put onto an available LWP many-to-one, many-to-many models process-contention scope, PCS Global Scheduling How the kernel decides which kernel thread to run next many-to-one, many-to-many & one-to-one models system-contention scope, SCS

Pthread Scheduling API I OS Examples for POSIX Pthread API allows specifying either PCS or SCS during thread creation PTHREAD SCOPE PROCESS, many-to-many PTHREAD SCOPE SYSTEM, one-to-one create and bind an LWP for each user-level thread example

Pthread Scheduling API II OS Examples for #include <pthreadh> #include <stdioh> #define NUM THREADS 5 int main(int argc, char *argv[]) { int i; pthread t tid[num THREADS]; pthread attr t attr; pthread attr init(&attr); /* get the default attributes */ /* set the scheduling algorithm to PROCESS or SYSTEM */ pthread attr setscope(&attr, PTHREAD SCOPE SYSTEM); /* set the scheduling policy - FIFO, RT, or OTHER */ pthread attr setschedpolicy(&attr, SCHED OTHER);

Pthread Scheduling API III OS Examples for for (i = 0; i < NUM THREADS; i++) /* create the threads */ pthread create(&tid[i],&attr,runner,null); } for (i = 0; i < NUM THREADS; i++) /* now join on each thread */ pthread join(tid[i], NULL); /* Each thread will begin control in this function */ void *runner(void *param) { printf( I am a thread\n ); pthread exit(0); }

Solaris scheduling I OS Examples for Solaris: priority-based thread scheduling 4 classes of scheduling, in order of priority Real time System (do not change the priority) Time sharing (default, with a multilevel feedback queue) Interactive, the same as time sharing, but higher priority Within each class there are different priorities and different scheduling algorithms

Solaris scheduling II OS Examples for

Solaris scheduling III Solaris Dispatch Table OS Examples for

Windows XP scheduling OS Examples for Dispatcher: priority-based, preemptive scheduling algorithm the dispatcher uses a-32 level priority scheme to determine the order of thread execution 0: idle thread 1 15: variable classes priorities 16 31: real-time class a queue for each priority Windows XP Priorities (policy classes, relative priority)

Outline 1 2 OS Examples for 3

小结 1 2 OS Examples for 3

作业 非华夏班 :51, 53 华夏班 :44, 47

上机作业 所有 : 写一个多线程的程序, 求素数 要求 1: 用户运行程序时在命令行输入一个素数, 然后程序创建一个独立新的线程来输出小于或等于用户所输入数的所有素数 要求 2: 采用两种 thread 来实现 pthread 或者 Windows thread 或者 Java thread 谢谢!