Motivation o Motivation In certain situations,a single application may be required to perform several similar tasks.Example:a web server Allow a server to service several concurrent requests.Example: an RPC server and Java's RMI systems The OS itself needs to perform some specific tasks in kernel, such as manging devices or interrupt handling. PARTICULAR,many OS systems are now multithreaded. Example:Solaris,Linux 口⊙卡生年12月00 陈适兰xlanchen@ustc.edu.cn http:/staf.u01174O1:Operating System操作系统原理 March29,20197/44
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Motivation Motivation ▶ In certain situations, a single application may be required to perform several similar tasks. Example: a web server ▶ Allow a server to service several concurrent requests. Example: an RPC server and Java’s RMI systems ▶ The OS itself needs to perform some specific tasks in kernel, such as manging devices or interrupt handling. ⋆ PARTICULAR, many OS systems are now multithreaded. ⋆ Example: Solaris, Linux 陈香兰 xlanchen@ustc.edu.cn http://staff.ustc.edu.cn/~xlanchen (Computer Application Laboratory, CS, USTC @ Hefei Embedded System Laboratory, CS, USTC @ Suzhou) 0117401: Operating System 操作系统原理与设计 March 29, 2019 7 / 44
Benefits Example:an interactive application such as web browser, while one thread loading an image,another thread allowing user interaction Resource Sharing address space,memory,and other resources Economy Solaris: creating a process is about 30 times slower then creating a thread; context switching is about 5 times slower Utilization of MP Architectures parallelism and concurrency 口18,走卡11月00 陈话兰xlanchen@ustc.edu:cn http/staff.u0117401 Operating System操作系统原理斐 March29,20198/44
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Benefits 1 Responsiveness (响应度高) ▶ Example: an interactive application such as web browser, while one thread loading an image, another thread allowing user interaction 2 Resource Sharing ▶ address space, memory, and other resources 3 Economy ▶ Solaris: creating a process is about 30 times slower then creating a thread; context switching is about 5 times slower 4 Utilization of MP Architectures ▶ parallelism and concurrency ↑ 陈香兰 xlanchen@ustc.edu.cn http://staff.ustc.edu.cn/~xlanchen (Computer Application Laboratory, CS, USTC @ Hefei Embedded System Laboratory, CS, USTC @ Suzhou) 0117401: Operating System 操作系统原理与设计 March 29, 2019 8 / 44
Outline 2Multithreading Models 口1⊙生年12月00 东香兰xanchen@ustc.edu.cn http:/staff..u011740i:Operating System操作系统原理斐 March29,20199/44
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Outline 2 Multithreading Models 陈香兰 xlanchen@ustc.edu.cn http://staff.ustc.edu.cn/~xlanchen (Computer Application Laboratory, CS, USTC @ Hefei Embedded System Laboratory, CS, USTC @ Suzhou) 0117401: Operating System 操作系统原理与设计 March 29, 2019 9 / 44
Two Methods Two methods to support threads o User threads VS.Kernel threads User threads Thread management done by user-level threads library without kernel support Kernel may be multithreaded or not. Three primary thread libraries: POSIX Pthreads Win32 threads Java threads 口18,走卡11月00 东香兰xanchen@ustc.edu.cn http:/staff..u011740i:Operating System操作系统原理斐 March29,201910/44
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Two Methods Two methods to support threads User threads VS. Kernel threads 1 User threads ▶ Thread management done by user-level threads library without kernel support ⋆ Kernel may be multithreaded or not. ▶ Three primary thread libraries: 1 POSIX Pthreads 2 Win32 threads 3 Java threads 陈香兰 xlanchen@ustc.edu.cn http://staff.ustc.edu.cn/~xlanchen (Computer Application Laboratory, CS, USTC @ Hefei Embedded System Laboratory, CS, USTC @ Suzhou) 0117401: Operating System 操作系统原理与设计 March 29, 2019 10 / 44
Two Methods Two methods to support threads o User threads VS.Kernel threads O Kernel Threads Supported by the Kernel,usually may be slower then user thread Examples Windows XP/2000 ★Solaris ★Linux Tru64 UNIX(formerly Digital UNIX) ★Mac OS X 口18走卡11月00 陈话兰xlanchen@ustc.edu:cn http/staff.u0117401 Operating System操作系统原理斐 March29,201910/44
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Two Methods Two methods to support threads User threads VS. Kernel threads 2 Kernel Threads ▶ Supported by the Kernel, usually may be slower then user thread ▶ Examples ⋆ Windows XP/2000 ⋆ Solaris ⋆ Linux ⋆ Tru64 UNIX (formerly Digital UNIX) ⋆ Mac OS X 陈香兰 xlanchen@ustc.edu.cn http://staff.ustc.edu.cn/~xlanchen (Computer Application Laboratory, CS, USTC @ Hefei Embedded System Laboratory, CS, USTC @ Suzhou) 0117401: Operating System 操作系统原理与设计 March 29, 2019 10 / 44