Figure 5.01

Similar documents
Microsoft PowerPoint os5.ppt [호환 모드]

Microsoft PowerPoint os4.ppt [호환 모드]

Microsoft PowerPoint os5.ppt

6주차.key

Microsoft PowerPoint - o4.pptx

Microsoft PowerPoint OS-Thread

강의10

untitled

PCServerMgmt7

침입방지솔루션도입검토보고서

APOGEE Insight_KR_Base_3P11

02 C h a p t e r Java

1


ESP1ºÎ-04

Deok9_Exploit Technique

Sena Technologies, Inc. HelloDevice Super 1.1.0

Chap7.PDF

No Slide Title

초보자를 위한 C++

PowerPoint 프레젠테이션

<C0CCBCBCBFB52DC1A4B4EBBFF82DBCAEBBE7B3EDB9AE2D D382E687770>

vm-웨어-앞부속

Backup Exec

Microsoft PowerPoint - o8.pptx

2009년도 한국멀티미디어학회 춘계학술발표대회 논문집 12권1호 1. 서론 게임을 개발하는 과정에서 게임 엔진은 자동차의 엔진과 같은 역할이다. 자동차의 가치를 평가하는 요소 중에 어떤 엔진을 적용 했는가는 자동차를 평가하는데 중요하다. 게임도 게임 개발 기술 중 엔진

Microsoft PowerPoint APUE(Intro).ppt

Microsoft PowerPoint - Lecture_Note_7.ppt [Compatibility Mode]

1217 WebTrafMon II

10주차.key

chap7.key

(Asynchronous Mode) ( 1, 5~8, 1~2) & (Parity) 1 ; * S erial Port (BIOS INT 14H) - 1 -

Something that can be seen, touched or otherwise sensed

(72) 발명자 이동희 서울 동작구 여의대방로44길 10, 101동 802호 (대 방동, 대림아파트) 노삼혁 서울 중구 정동길 21-31, B동 404호 (정동, 정동상 림원) 이 발명을 지원한 국가연구개발사업 과제고유번호 부처명 교육과학기술부

FMX M JPG 15MB 320x240 30fps, 160Kbps 11MB View operation,, seek seek Random Access Average Read Sequential Read 12 FMX () 2

Chap04(Signals and Sessions).PDF

Special Theme _ 모바일웹과 스마트폰 본 고에서는 모바일웹에서의 단말 API인 W3C DAP (Device API and Policy) 의 표준 개발 현황에 대해서 살펴보고 관 련하여 개발 중인 사례를 통하여 이해를 돕고자 한다. 2. 웹 애플리케이션과 네이

thesis

The Self-Managing Database : Automatic Health Monitoring and Alerting

vm-웨어-01장

PowerPoint 프레젠테이션

Solaris Express Developer Edition

untitled

13주-14주proc.PDF

Microsoft PowerPoint os5.ppt [호환 모드]

GNU/Linux 1, GNU/Linux MS-DOS LOADLIN DOS-MBR LILO DOS-MBR LILO... 6

K&R2 Reference Manual 번역본

Integ

CD-RW_Advanced.PDF

Microsoft Word - Automap3

01-OOPConcepts(2).PDF


KDTÁ¾ÇÕ-1-07/03

PowerPoint 프레젠테이션

인문사회과학기술융합학회

05-class.key

초보자를 위한 자바 2 21일 완성 - 최신개정판

Domino Designer Portal Development tools Rational Application Developer WebSphere Portlet Factory Workplace Designer Workplace Forms Designer

untitled

05Àå

PowerPoint 프레젠테이션

!K_InDesginCS_NFH

목 차 Ⅰ. 일반사항 1 Ⅱ. 특기사항 3 Ⅲ. 물품내역 및 세부규격 8 Ⅳ. 주의사항

Here is a "PLDWorld.com"... // EXCALIBUR... // Additional Resources // µc/os-ii... Page 1 of 23 Additional Resources: µc/os-ii Author: Source: HiTEL D

Microsoft PowerPoint - 11_Thread

Interstage5 SOAP서비스 설정 가이드

Microsoft PowerPoint - chap02-C프로그램시작하기.pptx

PowerPoint 프레젠테이션

KDTÁ¾ÇÕ-2-07/03

PowerPoint 프레젠테이션

05( ) CPLV12-04.hwp

hlogin2

hlogin7

Analyst Briefing

김기남_ATDC2016_160620_[키노트].key

제11장 프로세스와 쓰레드

Microsoft PowerPoint - StallingsOS6e-Chap04.pptx

, ( ) 1) *.. I. (batch). (production planning). (downstream stage) (stockout).... (endangered). (utilization). *

Alternating Sequence of CPU And I/O Bursts 6.2

Windows Embedded Compact 2013 [그림 1]은 Windows CE 로 알려진 Microsoft의 Windows Embedded Compact OS의 history를 보여주고 있다. [표 1] 은 각 Windows CE 버전들의 주요 특징들을 담고

Chap06(Interprocess Communication).PDF

ecorp-프로젝트제안서작성실무(양식3)

Microsoft Word - ExecutionStack

PowerPoint 프레젠테이션

Remote UI Guide

목 차

untitled

슬라이드 1

KEY 디바이스 드라이버

example code are examined in this stage The low pressure pressurizer reactor trip module of the Plant Protection System was programmed as subject for

Chapter_02-3_NativeApp

[Brochure] KOR_TunA

PowerPoint 프레젠테이션

Microsoft PowerPoint - a10.ppt [호환 모드]

Deok9_PE Structure

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

BMP 파일 처리

2013년 1회 정보처리산업기사 실기.hwp

Microsoft PowerPoint - [2009] 02.pptx

Transcription:

Chapter 4: Threads Yoon-Joong Kim Hanbat National University, Computer Engineering Department

Chapter 4: Multithreaded Programming Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads

4.1 Overview Thread 프로세스에소속된다. 구성요소 : Program counter, register set, stack space 나머지는공유 CPU 스케줄링의기본단위 Dynamic IWP,lightweight process 경량프로세스의문맥교환 ( CPU switching, thread context switch ) : 레지스터세트교환만 ( 예 1) web browser image 와 text 를 display 하는 thread network 에서데이터를가져오는 thread ( 예 2) word processor - graphics 를 display 하는 thread, keystrokes 를읽어오는 thread, spelling 과 grammar 를검사하는 thread Process 다중쓰레드를갖을수있다. code,data section, heap, OS resources ( 쓰레들이공유 ) 와쓰레드들 쓰레드의콘테이너 static A traditional or heavyweight process : a task with one thread 중량프로세스의문맥교환 ( process switching, context switching ) 레지스터세트교환과메모리관련작업도 (virtual memory page table 변경등 )

4.1 Overview(cont.) Fig. 4.1 Single and Multithreaded Processes

4.1 Overview(cont.) Address Space of process and thread Process Address Space ProcessAddress Space with Threads

4.1 Overview(cont.) 제어방식비교 다중스레드제어 (multiple-thread control) : 자신의 PC, stack, 비독립적 (no protection) 다중프로세스제어 (multiple-process control) : 자신의 PC, stack, address space, 독립적 (protection) 스레드의특성 CPU 공유 준비, 수행, 대기상태 자식 thread 생성 block ( 예 ) 생산자소비자문제 2 threads 로구현하면좋음 (better if on 2 processors) ( 예 ) 웹서버구현 Single process architecture : client 의요청을대기해야한다. 대기시간이매우길어짐 Multiple process architecture : client 의요청이있을때새 process 생성, overhead Multithreaded server architecture : client 의요청이있을때새 thread 생성하여서비스한다, 효율적 Thread 의장점 빠른응답 (responsiveness) 자원공유 (resource sharing) 경제성 (economy) 다중처리기구조이용 (utilization of multiprocessor architecture)

4.1 Overview(cont.) User-level Threads vs. Kernel-level Threads User-level threads user level 의 thread library 에서구현 : 라이브러리가 thread 생성, 스케줄링, 관리담당 불공평한스케줄링 (unfair scheduling) 스위칭이빠름 (switching is fast) single thread 인 kernel 에서사용자수준스레드가 blocking I/O system call 을수행핛경우 system call 완료까지다른모든스레드들은대기해야함 Kernel-level threads 커널이 thread 생성, 스케줄링, 관리담당 공평한스케줄링 (fair scheduling) 스위칭시간이김 (switching is time consuming) : interrupt 처리때문 blocking I/O system call 수행시커널이다른 thread 실행시킬수있음 Three primary thread libraries: POSIX pthreads: POSIX (Portable Operating System Interface) standard (IEEE 1003.1c) APIs (Solaris, Linux, Mac OS X) Java Threads Win32 Threads Examples Windows XP/2000 Solaris Linux Tru64 UNIX Mac OS X

4.1 Overview(cont.) User-level Threads vs. Kernel-level Threads

4.2 Multithread Model 4.2.1 Many-to-One Many user-level threads mapped to single kernel thread 한 thread 가 blocking system call 하면전체프로세스 block Examples: 초기의 Solaris Green Threads GNU Portable Threads

4.2 Multithread Model(cont.) 4.2.2 One-to-One Each user-level thread maps to kernel thread 한 thread 가 blocking system call 해도다른 thread 실행가능 User thread 생성마다 kernel thread 생성해야함 동시성이좋음 (more concurrency): multiprocessors 에서병렬처리 (parallel processing) 가능 Examples Windows 95,98,NT/XP/2000 Linux, Os2 Solaris 9 이후버전

4.2 Multithread Model(cont.) 4.2.3 Many-to-Many Model Allows many user level threads to be mapped to many kernel threads Allows the operating system to create a sufficient number of kernel threads 동시성이덜좋음 (less concurrency): 커널은한순간에하나의 kernel thread 만스케줄 특별한경우 : two-level model: 하나의 user-level thread 가하나의 kernel thread 로연결되는경우도지원 : Solaris 8 과이전버전, IRIX, Digital Unix, HP Tru64 UNIX Examples : Solaris 9 이전버전, Windows NT/2000 with the ThreadFiber package

4.2 Multithread Model(cont.) Two-level Model Similar to M:M, except that it allows a user thread to be bound to kernel thread Examples IRIX HP-UX Tru64 UNIX Solaris 8 and earlier

pthreads (thrd-posix.c) 4.3 Thread Libraries #include <pthread.h> #include <stdio.h> int sum; /* this data is shared by the thread(s) */ void *runner(void *param); /* the thread */ main(int argc, char *argv[]) { pthread_t tid; /* the thread identifier */ pthread_attr_t attr; /* set of attributes for the thread */ /* get the default attributes */ pthread_attr_init(&attr); /* create the thread */ pthread_create(&tid,&attr,runner,argv[1]); /* now wait for the thread to exit */ pthread_join(tid,null); printf("sum = %d\n",sum); } void *runner(void *param) { int upper = atoi(param); int i; sum = 0; if (upper > 0) { for (i = 1; i <= upper; i++) sum += i; } pthread_exit(0); }

Win 32 API( C ) /** * This program creates a separate thread using the CreateThread() system c * * Figure 4.10 * * @author Gagne, Galvin, Silberschatz * Operating System Concepts - Eighth Edition * Copyright John Wiley & Sons - 2009. */ #include <stdio.h> #include <windows.h> int main(int argc, char *argv[]) { DWORD ThreadId; HANDLE ThreadHandle; int Param; // do some basic error checking if (argc!= 2) { fprintf(stderr,"an integer parameter is required\n"); return -1; } Param = atoi(argv[1]); DWORD Sum; /* data is shared by the thread(s) */ /* the thread runs in this separate function */ DWORD WINAPI Summation(PVOID Param) { DWORD Upper = *(DWORD *)Param; } for (DWORD i = 0; i <= Upper; i++) Sum += i; return 0; } if (Param < 0) { fprintf(stderr, "an integer >= 0 is required \n"); return -1; } // create the thread ThreadHandle = CreateThread(NULL, 0, Summation, &Param, 0, &ThreadId); if (ThreadHandle!= NULL) { WaitForSingleObject(ThreadHandle, INFINITE); CloseHandle(ThreadHandle); printf("sum = %d\n",sum); }

Thread class in C#

Simple threading scenario ( C# )

Simple threading scenario ( C# ) int sum=0; Main thread t2.start() t3.start(8) Do some work Do some work Do some work Do some work t2.join() write(sum) t3.join(8) 2nd thread Write 2 nd Th.. Write 2 nd Th.. Write 2 nd Th.. Write 2 nd Th.. sum=6 3nd thread Write 3rd Th.. Write 3rd Th.. Write 3rd Th.. Write 3rd Th.. Write 3rd Th.. Write 3rd Th.. Write 3rd Th..