Thread Libraries I o A thread library provides an APl for creating and managing threads. Two primary ways to provide a library entirely in user space with no kernel support to implement a kernel-level library supported directly by the oS library code data API invoking method inside APl user-level entirely in user space user space a local function call kernel-level kernel space user space system call o Two general strategies Asynchronous threading threads are independent with little data sharing Synchronous threading or fork-join strategy parent waits until all children have joined involves significant data sharing among threads 东香兰xlanchen@ustc,edu.cn http:/staff..u011740i:Operating System操作系统原理 March29,201913/44
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Thread Libraries I A thread library provides an API for creating and managing threads. Two primary ways 1 to provide a library entirely in user space with no kernel support 2 to implement a kernel-level library supported directly by the OS library code & data API invoking method inside API user-level entirely in user space user space a local function call kernel-level kernel space user space system call Two general strategies ▶ Asynchronous threading ⋆ threads are independent with little data sharing ▶ Synchronous threading or fork-join strategy ⋆ parent waits until all children have joined ⋆ involves significant data sharing among 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 13 / 44
Thread Libraries Il o Three main thead libraries POSIX Pthreads ②Win32 threads Java threads Example:a multithreaded program o Summation: N sum =i i=0 口18走卡11月00 陈香兰xlanchen@ustc.edu.cn http:/taf.u0117401:Operating System操作系统原理 March29,201914/44
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Thread Libraries II Three main thead libraries 1 POSIX Pthreads 2 Win32 threads 3 Java threads Example: a multithreaded program Summation: sum = N Σi i=0 陈香兰 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 14 / 44