Chapter 4: Threads. Operating System Concepts 9 th Edition
|
|
- Cecil Carter
- 5 years ago
- Views:
Transcription
1 Chapter 4: Threads Silberschatz, Galvin and Gagne 2013
2 Objectives To introduce the notion of a thread a fundamental unit of CPU utilization that forms the basis of multithreaded computer systems To discuss the APIs for the Pthreads, Windows, and Java thread libraries To explore several strategies that provide implicit threading To examine issues related to multithreaded programming To cover operating system support for threads in Windows and Linux 4.2 Silberschatz, Galvin and Gagne 2013
3 Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Operating System Examples 4.3 Silberschatz, Galvin and Gagne 2013
4 Warm-up Discussion: What is abstraction? What is our first abstraction? Why we need it? A new abstraction for a single running process: the thread. Why we need this abstraction? Thinking of: Some programs have more than one point of execution (i.e., multiple PCs). Example #1: adding two large arrays together Discussion: how to speed up execution? Example #2: some elements need input Discussion: how to speed up execution? Discussion: Why multiple threads, not multiple processes? 4.4 Silberschatz, Galvin and Gagne 2013
5 Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Operating System Examples 4.5 Silberschatz, Galvin and Gagne 2013
6 Motivation Most modern applications are multithreaded Threads run within application Multiple tasks with the application can be implemented by separate threads Update display Fetch data Spell checking Answer a network request Process creation is heavy-weight while thread creation is light-weight Can simplify code, increase efficiency Kernels are generally multithreaded 4.6 Silberschatz, Galvin and Gagne 2013
7 Benefits Responsiveness may allow continued execution if part of process is blocked, especially important for user interfaces Resource Sharing threads share resources of process, easier than shared memory or message passing Economy cheaper than process creation, thread switching lower overhead than context switching Scalability process can take advantage of multiprocessor architectures 4.7 Silberschatz, Galvin and Gagne 2013
8 Single and Multithreaded Processes 4.8 Silberschatz, Galvin and Gagne 2013
9 Multithreaded Server Architecture 4.9 Silberschatz, Galvin and Gagne 2013
10 Multithreading MS-DOS JRE UNIX Most modern OS 4.10 Silberschatz, Galvin and Gagne 2013
11 Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Operating System Examples 4.11 Silberschatz, Galvin and Gagne 2013
12 Multicore Programming Multicore or multiprocessor systems putting pressure on programmers, challenges include: Dividing activities Balance Data splitting Data dependency Testing and debugging Parallelism implies a system can perform more than one task simultaneously Concurrency supports more than one task making progress Single processor / core, scheduler providing concurrency 4.12 Silberschatz, Galvin and Gagne 2013
13 Concurrency vs. Parallelism Concurrent execution on single-core system: Parallelism on a multi-core system: 4.13 Silberschatz, Galvin and Gagne 2013
14 Multicore Programming (Cont.) Types of parallelism Data parallelism distributes subsets of the same data across multiple cores, same operation on each Task parallelism distributing threads across cores, each thread performing unique operation As # of threads grows, so does architectural support for threading CPUs have cores as well as hardware threads Consider Oracle SPARC T4 with 8 cores, and 8 hardware threads per core Discussion: How much performance can we gain from adding additional cores? Suppose we have N processing cores Silberschatz, Galvin and Gagne 2013
15 Amdahl s Law Identifies performance gains from adding additional cores to an application that has both serial and parallel components S is serial portion N processing cores That is, if application is 75% parallel / 25% serial, moving from 1 to 2 cores results in speedup of 1.6 times As N approaches infinity, speedup approaches 1 / S Serial portion of an application has disproportionate effect on performance gained by adding additional cores But does the law take into account contemporary multicore systems? 4.15 Silberschatz, Galvin and Gagne 2013
16 Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Operating System Examples 4.16 Silberschatz, Galvin and Gagne 2013
17 User Threads and Kernel Threads Who/How to provide support for threads? User threads - management done by user-level threads library Three primary thread libraries: POSIX Pthreads Windows threads Java threads Kernel threads - Supported by the Kernel Examples virtually all general purpose operating systems, including: Windows Solaris Linux Tru64 UNIX Mac OS X 4.17 Silberschatz, Galvin and Gagne 2013
18 Implementing Threads in Kernel/User Space 4.18 Silberschatz, Galvin and Gagne 2013
19 Motivating Kernel/User Threads Why we need user threads? There is no kernel intervention, and, hence, user threads are usually more efficient. Why user threads are not enough? Unfortunately, since the kernel only recognizes the containing process (of the threads), if one thread is blocked, every other threads of the same process are also blocked because the containing process is blocked. Why we need kernel threads? However, blocking one thread will not cause other threads of the same process to block. The kernel simply runs other threads. In a multiprocessor environment, the kernel can schedule threads on different processors Why kernel threads are not enough? Kernel threads are usually slower than the user threads Silberschatz, Galvin and Gagne 2013
20 Multithreading Models Many-to-One One-to-One Many-to-Many 4.20 Silberschatz, Galvin and Gagne 2013
21 Many-to-One Many user-level threads mapped to single kernel thread One thread blocking causes all to block Question: reason? Multiple threads may not run in parallel on multicore system Question: reason? Used on systems that do not support kernel threads. Few systems currently use this model Examples: Solaris Green Threads GNU Portable Threads 4.21 Silberschatz, Galvin and Gagne 2013
22 One-to-One Each user-level thread maps to kernel thread Creating a user-level thread creates a kernel thread More concurrency than many-to-one Number of threads per process sometimes restricted due to overhead Examples Windows Linux Solaris 9 and later 4.22 Silberschatz, Galvin and Gagne 2013
23 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 Examples Solaris prior to version 9 Windows with the ThreadFiber package 4.23 Silberschatz, Galvin and Gagne 2013
24 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 4.24 Silberschatz, Galvin and Gagne 2013
25 Aside Question: Among the three models, which model(s) are general in modern systems? M:M for server 1:1 for PC To improve LinuxThreads, two competing projects were started to develop a replacement; NGPT (Next Generation POSIX Threads from IBM) and NPTL (Native POSIX Thread Library from Red Hat). NPTL won out and is today shipped with the vast majority of Linux systems NGPT M:M NPTL 1: Silberschatz, Galvin and Gagne 2013
26 Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Operating System Examples 4.26 Silberschatz, Galvin and Gagne 2013
27 Thread Libraries Thread library provides programmer with API for creating and managing threads Two primary ways of implementing Library entirely in user space Kernel-level library supported by the OS Three main thread libraries POSIX Pthreads Windows Java 4.27 Silberschatz, Galvin and Gagne 2013
28 Pthreads May be provided either as user-level or kernel-level A POSIX standard (IEEE c) API for thread creation and synchronization Specification, not implementation API specifies behavior of the thread library, implementation is up to development of the library Common in UNIX operating systems (Solaris, Linux, Mac OS X) 4.28 Silberschatz, Galvin and Gagne 2013
29 Pthread Creation 1. Which thread is to be created? A pointer to structure of this thread. 2. What kind of thread is it? The stack size and priority information, etc. 3. How to run the thread? The thread entry function (function pointer in C). 4. With what arguments? Arg. Aside: why void *? void * itself is an abstraction. Having a void pointer as an argument to the function start routine allows us to pass in any type of argument; Having it as a return value allows the thread to return any type of result Silberschatz, Galvin and Gagne 2013
30 Pthread Creation Discussion: What is the output? 4.30 Silberschatz, Galvin and Gagne 2013
31 Pthread Completion Wait for completion 1. Which thread is to be completed? The pointer to structure of this thread. 2. What is the return value? void ** Silberschatz, Galvin and Gagne 2013
32 Pthread Completion Discussion: What is the output? 4.32 Silberschatz, Galvin and Gagne 2013
33 Pthreads Example 4.33 Silberschatz, Galvin and Gagne 2013
34 Pthreads Example (Cont.) 4.34 Silberschatz, Galvin and Gagne 2013
35 Pthreads Code for Joining 10 Threads 4.35 Silberschatz, Galvin and Gagne 2013
36 Windows Multithreaded C Program 4.36 Silberschatz, Galvin and Gagne 2013
37 Windows Multithreaded C Program (Cont.) 4.37 Silberschatz, Galvin and Gagne 2013
38 Java Threads Java threads are managed by the JVM Typically implemented using the threads model provided by underlying OS Java threads may be created by: Extending Thread class Implementing the Runnable interface 4.38 Silberschatz, Galvin and Gagne 2013
39 Java Multithreaded Program 4.39 Silberschatz, Galvin and Gagne 2013
40 Java Multithreaded Program (Cont.) Discussion: When this program runs, how many threads are created in the JVM? 4.40 Silberschatz, Galvin and Gagne 2013
41 Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Operating System Examples 4.41 Silberschatz, Galvin and Gagne 2013
42 Implicit Threading Growing in popularity as numbers of threads increase, program correctness more difficult with explicit threads Creation and management of threads done by compilers and run-time libraries rather than programmers Why in this way difficulties can be solved? Three methods explored Thread Pools OpenMP Grand Central Dispatch Other methods include Microsoft Threading Building Blocks (TBB), java.util.concurrent package 4.42 Silberschatz, Galvin and Gagne 2013
43 Thread Pools Create a number of threads in a pool where they await work Advantages: Usually slightly faster to service a request with an existing thread than create a new thread (Reason?) Allows the number of threads in the application(s) to be bound to the size of the pool (Reason?) Separating task to be performed from mechanics of creating task allows different strategies for running task (Reason?) i.e. Tasks could be scheduled to run periodically Windows API supports thread pools: 4.43 Silberschatz, Galvin and Gagne 2013
44 OpenMP Set of compiler directives and an API for C, C++, FORTRAN Provides support for parallel programming in shared-memory environments Identifies parallel regions blocks of code that can run in parallel #pragma omp parallel Create as many threads as there are cores #pragma omp parallel for for(i=0;i<n;i++) { c[i] = a[i] + b[i]; } Run for loop in parallel 4.44 Silberschatz, Galvin and Gagne 2013
45 Grand Central Dispatch Apple technology for Mac OS X and ios operating systems Extensions to C, C++ languages, API, and run-time library Allows identification of parallel sections Manages most of the details of threading Block is in ^{ } - ˆ{ printf("i am a block"); } Blocks placed in dispatch queue Assigned to available thread in thread pool when removed from queue 4.45 Silberschatz, Galvin and Gagne 2013
46 Grand Central Dispatch Two types of dispatch queues: serial blocks removed in FIFO order, queue is per process, called main queue Programmers can create additional serial queues within program concurrent removed in FIFO order but several may be removed at a time Three system wide queues with priorities low, default, high 4.46 Silberschatz, Galvin and Gagne 2013
47 Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Operating System Examples 4.47 Silberschatz, Galvin and Gagne 2013
48 Threading Issues Semantics of fork() and exec() system calls Thread cancellation of target thread Asynchronous or deferred Signal handling Synchronous and asynchronous Thread-local storage Scheduler Activations 4.48 Silberschatz, Galvin and Gagne 2013
49 Semantics of fork() and exec() If one thread in a program calls fork(), does the new process duplicate all threads, or is the new process single-threaded? Two versions of fork(). What about exec()? Replace the entire process, including all thread. Discussion: If exec() is called immediately after forking, which version of fork() do you prefer? If exec() is called immediately after forking, then duplicating all threads is unnecessary 4.49 Silberschatz, Galvin and Gagne 2013
50 Thread Cancellation Terminating a thread before it has finished Thread to be canceled is target thread Two general approaches: Asynchronous cancellation terminates the target thread immediately Deferred cancellation allows the target thread to periodically check if it should be cancelled Pthread code to create and cancel a thread: 4.50 Silberschatz, Galvin and Gagne 2013
51 Thread Cancellation (Cont.) Invoking thread cancellation requests cancellation, but actual cancellation depends on thread state If thread has cancellation disabled, cancellation remains pending until thread enables it Default type is deferred Cancellation only occurs when thread reaches cancellation point I.e. pthread_testcancel() Then cleanup handler is invoked On Linux systems, thread cancellation is handled through signals 4.51 Silberschatz, Galvin and Gagne 2013
52 Signal Handling n n n Signals are used in UNIX systems to notify a process that a particular event has occurred. A signal handler is used to process signals 1. Signal is generated by particular event 2. Signal is delivered to a process 3. Signal is handled by one of two signal handlers: 1. default 2. user-defined Every signal has default handler that kernel runs when handling signal l l User-defined signal handler can override default For single-threaded, signal delivered to process 4.52 Silberschatz, Galvin and Gagne 2013
53 Portable Signal Default Action Description number SIGABRT 6 Terminate (core Signal dump) Handling Process abort signal SIGALRM 14 Terminate Alarm clock SIGBUS N/A Terminate (core dump) Access to an undefined portion of a memory object. SIGCHLD N/A Ignore Child process terminated, stopped, or continued. SIGCONT N/A Continue Continue executing, if stopped. SIGFPE N/A Terminate (core dump) Erroneous arithmetic operation. SIGHUP 1 Terminate Hangup. SIGILL N/A Terminate (core dump) Illegal instruction. SIGINT 2 Terminate Terminal interrupt signal. SIGKILL 9 Terminate Kill (cannot be caught or ignored). SIGPIPE N/A Terminate Write on a pipe with no one to read it. SIGPOLL N/A Terminate Pollable event. SIGPROF N/A Terminate Profiling timer expired. SIGQUIT 3 Terminate (core dump) Terminal quit signal. SIGSEGV N/A Terminate (core dump) Invalid memory reference. SIGSTOP N/A Stop Stop executing (cannot be caught or ignored). SIGSYS N/A Terminate (core dump) Bad system call. SIGTERM 15 Terminate Termination signal. SIGTRAP 5 Terminate (core dump) Trace/breakpoint trap. SIGTSTP N/A Stop Terminal stop signal. SIGTTIN N/A Stop Background process attempting read. SIGTTOU N/A Stop Background process attempting write. SIGURG N/A Ignore High bandwidth data is available at a socket. SIGUSR1 N/A Terminate User-defined signal 1. SIGUSR2 N/A Terminate User-defined signal 2. SIGVTALRM N/A Terminate Virtual timer expired. SIGWINCH N/A Ignore Terminal window size changed SIGXCPU N/A Terminate (core dump) CPU time limit exceeded. SIGXFSZ Operating System Concepts N/A 9 th Edition Terminate (core dump) 4.53 File size limit exceeded Silberschatz, Galvin and Gagne 2013
54 Signal Handling (Cont.) n Where should a signal be delivered for multi-threaded? l l l l Deliver the signal to the thread to which the signal applies Deliver the signal to every thread in the process Deliver the signal to certain threads in the process Assign a specific thread to receive all signals for the process l Discussion: Can a thread have its own handler? l All threads in a process share a same signal handler, which can be either a default one or a user-defined one (overridden) Silberschatz, Galvin and Gagne 2013
55 Thread-Local Storage Question: How to achieve parallelism in executing counter ++? Each thread counts, and summarize when needed. Question: Is counter shared by all threads in the process, or owned by each thread? Not shared within the process, also not in thread stacks. Thread-local storage (TLS) allows each thread to have its own copy of data Useful when you do not have control over the thread creation process (i.e., when using a thread pool) Different from local variables Local variables visible only during single function invocation TLS visible across function invocations Similar to static data TLS is unique to each thread Discussion: Why not use the thread stack? Life cycle reasons. Local variables are in thread stack 4.55 Silberschatz, Galvin and Gagne 2013
56 Scheduler Activations In M:M or Two-level model, how to maintain a appropriate number of kernel threads allocated to the application? Communication, but how? Typically use an intermediate data structure between user and kernel threads lightweight process (LWP) Appears to be a virtual processor on which process can schedule user thread to run Each LWP attached to kernel thread How many LWPs to create? Scheduler activations provide upcalls -a communication mechanism from the kernel to the upcall handler in the thread library. (vs. downcalls) This communication allows an application to maintain the correct number kernel threads 4.56 Silberschatz, Galvin and Gagne 2013
57 Scheduler Activations Question: Suppose an I/O-bound application which has five different file-read requests occur simultaneously. At some moment, two kernel threads are allocated to the application. How many LWPs are created? At some other moment, one kernel thread blocks (waiting for I/O completion) T/F? This kernel thread makes an upcall, and the attached LWP blocks the current user thread, and schedules another user thread to run. T/F? The attached LWP also blocks. The kernel makes an upcall and then allocates a new LWP to the application. After returning from upcall handling, how many LWPs now? If we wish to run this application efficiently, how many LWPs are needed for this application Silberschatz, Galvin and Gagne 2013
58 Exercise 4.1 是资源分配的最小单位 是 CPU 调度的最小单位 A B C D E 进程线程轻量级进程 (LWP) 内核线程用户线程 4.58 Silberschatz, Galvin and Gagne 2013
59 Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Operating System Examples 4.59 Silberschatz, Galvin and Gagne 2013
60 Operating System Examples Windows Threads Linux Threads 4.60 Silberschatz, Galvin and Gagne 2013
61 Windows Threads Windows implements the Windows API primary API for Win 98, Win NT, Win 2000, Win XP, and Win 7 Implements the one-to-one mapping, kernel-level Each thread contains A thread id Register set representing state of processor Separate user and kernel stacks for when thread runs in user mode or kernel mode Private data storage area used by run-time libraries and dynamic link libraries (DLLs) The register set, stacks, and private storage area are known as the context of the thread 4.61 Silberschatz, Galvin and Gagne 2013
62 Windows Threads (Cont.) The primary data structures of a thread include: ETHREAD (executive thread block) includes pointer to process to which thread belongs and to KTHREAD, in kernel space KTHREAD (kernel thread block) scheduling and synchronization info, kernel-mode stack, pointer to TEB, in kernel space TEB (thread environment block) thread id, user-mode stack, thread-local storage, in user space 4.62 Silberschatz, Galvin and Gagne 2013
63 Windows Threads Data Structures 4.63 Silberschatz, Galvin and Gagne 2013
64 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) Flags control behavior struct task_struct points to process data structures (shared or unique) 4.64 Silberschatz, Galvin and Gagne 2013
65 Review What are the differences and relations between a process and a thread? What are the differences between a kernel thread and a user thread? What are M:1, 1:1, M:M models? Compare signal and interrupt. 实验 : 多进程 / 线程编程实现矩阵乘法 1. Linux 下进程的创建 : 函数 fork() 和 exec( ) 的使用 2. Linux/Windows 下多线程编程实现矩阵乘法 3. 每个乘积矩阵元素的计算过程均由一个独立线程实现 4.65 Silberschatz, Galvin and Gagne 2013
66 More Complex Example What are possible outputs of the program? void * hellofunc ( void * ptr ) { int *data; data = (int *) ptr; printf( I m Thread %d \n, *data); } int main() { pthread_t hthread[4]; for (int i = 0; i < 4; i++) pthread_create(&hthread[i], NULL, hellofunc, (void *)&i); for (int i = 0; i < 4; i++) pthread_join(hthread[i], NULL); return 0; } 4.66 Silberschatz, Galvin and Gagne 2013
67 More Complex Example Non-decreasing sequence satisfying Output Line #1 Output Line #2 Output Line #3 Output Line #4 Possible Outputs 4.67 Silberschatz, Galvin and Gagne 2013
68 End of Chapter 4 Silberschatz, Galvin and Gagne 2013
Chapter 4: Threads. Chapter 4: Threads
Chapter 4: Threads Silberschatz, Galvin and Gagne 2013 Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Operating System Examples
More informationOPERATING SYSTEM. Chapter 4: Threads
OPERATING SYSTEM Chapter 4: Threads Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Operating System Examples Objectives To
More informationChapter 4: Threads. Chapter 4: Threads. Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues
Chapter 4: Threads Silberschatz, Galvin and Gagne 2013 Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues 4.2 Silberschatz, Galvin
More informationChapter 4: Threads. Operating System Concepts 9 th Edition
Chapter 4: Threads Silberschatz, Galvin and Gagne 2013 Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Operating System Examples
More informationChapter 4: Threads. Operating System Concepts 9 th Edit9on
Chapter 4: Threads Operating System Concepts 9 th Edit9on Silberschatz, Galvin and Gagne 2013 Chapter 4: Threads 1. Overview 2. Multicore Programming 3. Multithreading Models 4. Thread Libraries 5. Implicit
More informationChapter 4: Threads. Operating System Concepts 9 th Edition
Chapter 4: Threads Silberschatz, Galvin and Gagne 2013 Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Operating System Examples
More informationChapter 4 Multithreaded Programming
Chapter 4 Multithreaded Programming Da-Wei Chang CSIE.NCKU Source: Abraham Silberschatz, Peter B. Galvin, and Greg Gagne, "Operating System Concepts", 9th Edition, Wiley. 1 1 Outline Overview Multithreading
More informationChapter 4: Multithreaded Programming
Chapter 4: Multithreaded Programming Silberschatz, Galvin and Gagne 2013 Chapter 4: Multithreaded Programming Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading
More informationEI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)
EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture) Dept. of Computer Science & Engineering Chentao Wu wuct@cs.sjtu.edu.cn Download lectures ftp://public.sjtu.edu.cn User:
More informationOperating Systems 2 nd semester 2016/2017. Chapter 4: Threads
Operating Systems 2 nd semester 2016/2017 Chapter 4: Threads Mohamed B. Abubaker Palestine Technical College Deir El-Balah Note: Adapted from the resources of textbox Operating System Concepts, 9 th edition
More informationChapter 4: Multi-Threaded Programming
Chapter 4: Multi-Threaded Programming Chapter 4: Threads 4.1 Overview 4.2 Multicore Programming 4.3 Multithreading Models 4.4 Thread Libraries Pthreads Win32 Threads Java Threads 4.5 Implicit Threading
More informationChapter 4: Threads. Chapter 4: Threads
Chapter 4: Threads Silberschatz, Galvin and Gagne 2009 Chapter 4: Threads Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads 4.2
More informationChapter 4: Multithreaded Programming
Chapter 4: Multithreaded Programming Silberschatz, Galvin and Gagne 2013! Chapter 4: Multithreaded Programming Overview Multicore Programming Multithreading Models Threading Issues Operating System Examples
More informationCSE 4/521 Introduction to Operating Systems
CSE 4/521 Introduction to Operating Systems Lecture 5 Threads (Overview, Multicore Programming, Multithreading Models, Thread Libraries, Implicit Threading, Operating- System Examples) Summer 2018 Overview
More informationChapter 4: Multithreaded Programming. Operating System Concepts 8 th Edition,
Chapter 4: Multithreaded Programming, Silberschatz, Galvin and Gagne 2009 Chapter 4: Multithreaded Programming Overview Multithreading Models Thread Libraries Threading Issues 4.2 Silberschatz, Galvin
More informationCS307: Operating Systems
CS307: Operating Systems Chentao Wu 吴晨涛 Associate Professor Dept. of Computer Science and Engineering Shanghai Jiao Tong University SEIEE Building 3-513 wuct@cs.sjtu.edu.cn Download Lectures ftp://public.sjtu.edu.cn
More informationLecture 4 Threads. (chapter 4)
Bilkent University Department of Computer Engineering CS342 Operating Systems Lecture 4 Threads (chapter 4) Dr. İbrahim Körpeoğlu http://www.cs.bilkent.edu.tr/~korpe 1 References The slides here are adapted/modified
More informationChapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads
Chapter 4: Threads Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads Chapter 4: Threads Objectives To introduce the notion of a
More informationCS420: Operating Systems
Threads James Moscola Department of Physical Sciences York College of Pennsylvania Based on Operating System Concepts, 9th Edition by Silberschatz, Galvin, Gagne Threads A thread is a basic unit of processing
More informationChapter 4: Multithreaded Programming Dr. Varin Chouvatut. Operating System Concepts 8 th Edition,
Chapter 4: Multithreaded Programming Dr. Varin Chouvatut, Silberschatz, Galvin and Gagne 2010 Chapter 4: Multithreaded Programming Overview Multithreading Models Thread Libraries Threading Issues Operating
More informationChapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads. Operating System Concepts
Chapter 4: Threads Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads 4.2 Silberschatz, Galvin and Gagne 2005 Single and Multithreaded
More informationChapter 4: Multithreaded Programming
Chapter 4: Multithreaded Programming Chapter 4: Multithreaded Programming Overview Multicore Programming Multithreading Models Threading Issues Operating System Examples Objectives To introduce the notion
More informationChapter 4: Multithreaded Programming
Chapter 4: Multithreaded Programming Chapter 4: Multithreaded Programming Overview Multicore Programming Multithreading Models Threading Issues Operating System Examples Objectives To introduce the notion
More informationI.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 4: MULTITHREADED PROGRAMMING
I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 4: MULTITHREADED PROGRAMMING Chapter 4: Multithreaded Programming Overview Multithreading Models Thread Libraries Threading
More informationQuestions from last time
Questions from last time Pthreads vs regular thread? Pthreads are POSIX-standard threads (1995). There exist earlier and newer standards (C++11). Pthread is probably most common. Pthread API: about a 100
More informationChapter 4: Threads. Operating System Concepts. Silberschatz, Galvin and Gagne
Chapter 4: Threads Silberschatz, Galvin and Gagne Chapter 4: Threads Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Linux Threads 4.2 Silberschatz, Galvin and
More informationChapter 5: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads
Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads 5.1 Silberschatz, Galvin and Gagne 2003 More About Processes A process encapsulates
More informationChapter 4: Multithreaded
Chapter 4: Multithreaded Programming Chapter 4: Multithreaded Programming Overview Multithreading Models Thread Libraries Threading Issues Operating-System Examples 2009/10/19 2 4.1 Overview A thread is
More informationChe-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University
Che-Wei Chang chewei@mail.cgu.edu.tw Department of Computer Science and Information Engineering, Chang Gung University 1. Introduction 2. System Structures 3. Process Concept 4. Multithreaded Programming
More informationCS 450 Operating System Week 4 Lecture Notes
CS 450 Operating System Week 4 Lecture Notes Reading: Operating System Concepts (7 th Edition) - Silberschatz, Galvin, Gagne Chapter 5 - Pages 129 147 Objectives: 1. Explain the main Objective of Threads
More informationThreads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits
CS307 What is a thread? Threads A thread is a basic unit of CPU utilization contains a thread ID, a program counter, a register set, and a stack shares with other threads belonging to the same process
More informationOutline. Threads. Single and Multithreaded Processes. Benefits of Threads. Eike Ritter 1. Modified: October 16, 2012
Eike Ritter 1 Modified: October 16, 2012 Lecture 8: Operating Systems with C/C++ School of Computer Science, University of Birmingham, UK 1 Based on material by Matt Smart and Nick Blundell Outline 1 Concurrent
More informationMultithreaded Programming
Multithreaded Programming The slides do not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams. September 4, 2014 Topics Overview
More informationCS370 Operating Systems
CS370 Operating Systems Colorado State University Yashwant K Malaiya Spring 2018 Lecture 7 Threads Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ How many processes can a core
More informationAgenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2
Lecture 3: Processes Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2 Process in General 3.3 Process Concept Process is an active program in execution; process
More informationCSE Opera,ng System Principles
CSE 30341 Opera,ng System Principles Lecture 5 Processes / Threads Recap Processes What is a process? What is in a process control bloc? Contrast stac, heap, data, text. What are process states? Which
More informationCS370 Operating Systems
CS370 Operating Systems Colorado State University Yashwant K Malaiya Spring 2018 Lecture 8 Threads and Scheduling Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ How many threads
More informationConcurrency, Thread. Dongkun Shin, SKKU
Concurrency, Thread 1 Thread Classic view a single point of execution within a program a single PC where instructions are being fetched from and executed), Multi-threaded program Has more than one point
More informationChapter 5: Processes & Process Concept. Objectives. Process Concept Process Scheduling Operations on Processes. Communication in Client-Server Systems
Chapter 5: Processes Chapter 5: Processes & Threads Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems, Silberschatz, Galvin and
More informationSemantics of fork() and exec()
Threads Week 3.2 Threading Issues Semantics of fork() and exec() system calls Signal handling Synchronous and asynchronous Thread cancellation of target thread Asynchronous or deferred Thread-local storage
More informationCSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song
CSCE 313 Introduction to Computer Systems Instructor: Dezhen Song Programs, Processes, and Threads Programs and Processes Threads Programs, Processes, and Threads Programs and Processes Threads Processes
More informationCSCE 313: Intro to Computer Systems
CSCE 313 Introduction to Computer Systems Instructor: Dr. Guofei Gu http://courses.cse.tamu.edu/guofei/csce313/ Programs, Processes, and Threads Programs and Processes Threads 1 Programs, Processes, and
More informationChapter 4: Threads. Operating System Concepts with Java 8 th Edition
Chapter 4: Threads 14.1 Silberschatz, Galvin and Gagne 2009 Chapter 4: Threads Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples 14.2 Silberschatz, Galvin and Gagne
More informationCS370 Operating Systems
CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 8 Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ How many partners can we cave for project:
More informationChapter 3: Processes. Operating System Concepts 8th Edition
Chapter 3: Processes Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication in Client-Server Systems 3.2 Objectives
More informationProcesses and Threads
TDDI04 Concurrent Programming, Operating Systems, and Real-time Operating Systems Processes and Threads [SGG7] Chapters 3 and 4 Copyright Notice: The lecture notes are mainly based on Silberschatz s, Galvin
More informationOperating Systems. Threads and Signals. Amir Ghavam Winter Winter Amir Ghavam
95.300 Operating Systems Threads and Signals Amir Ghavam Winter 2002 1 Traditional Process Child processes created from a parent process using fork Drawbacks Fork is expensive: Memory is copied from a
More informationSystem Programming. Signals I
Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Introduction 2 3 Signals
More informationChapter 5: Threads. Outline
Department of Electr rical Eng ineering, Chapter 5: Threads 王振傑 (Chen-Chieh Wang) ccwang@mail.ee.ncku.edu.tw ncku edu Feng-Chia Unive ersity Outline Overview Multithreading Models Threading Issues 2 Depar
More informationChapter 5: Threads. Single and Multithreaded Processes
Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads Chapter 5: Threads 5.1 Silberschatz, Galvin and Gagne 2003 Single and Multithreaded Processes 5.2
More informationOperating Systems Prof. Ashok K Agrawala
CSMC 412 Operating Systems Prof. Ashok K Agrawala 2005 Ashok Agrawala Set 4 4.1 Silberschatz, Galvin and Gagne 2005 Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux
More informationRicardo Rocha. Department of Computer Science Faculty of Sciences University of Porto
Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Slides based on the book Operating System Concepts, 9th Edition, Abraham Silberschatz, Peter B. Galvin and Greg Gagne,
More informationCISC2200 Threads Spring 2015
CISC2200 Threads Spring 2015 Process We learn the concept of process A program in execution A process owns some resources A process executes a program => execution state, PC, We learn that bash creates
More informationChapter 4: Threads. Operating System Concepts 8 th Edition,
Chapter 4: Threads, Silberschatz, Galvin and Gagne 2009 Chapter 4: Threads Overview Multithreading Models Thread Libraries 4.2 Silberschatz, Galvin and Gagne 2009 Objectives To introduce the notion of
More informationCOP 4610: Introduction to Operating Systems (Spring 2015) Chapter 4: Threads. Zhi Wang Florida State University
COP 4610: Introduction to Operating Systems (Spring 2015) Chapter 4: Threads Zhi Wang Florida State University Contents Thread overview Multithreading models Thread libraries Threading issues Operating
More informationProcesses and Threads
Processes and Threads Giuseppe Anastasi g.anastasi@iet.unipi.it Pervasive Computing & Networking Lab. () Dept. of Information Engineering, University of Pisa Based on original slides by Silberschatz, Galvin
More informationProcess Description and Control
Process Description and Control 1 Process:the concept Process = a program in execution Example processes: OS kernel OS shell Program executing after compilation www-browser Process management by OS : Allocate
More informationCS370 Operating Systems
CS370 Operating Systems Colorado State University Yashwant K Malaiya Spring 2019 Lecture 7 Threads Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Amdahls law example: Person
More informationSignals. Joseph Cordina
1 Signals Signals are software interrupts that give us a way to handle asynchronous events. Signals can be received by or sent to any existing process. It provides a flexible way to stop execution of a
More informationCOSC243 Part 2: Operating Systems
COSC243 Part 2: Operating Systems Lecture 16: Threads and data sharing Zhiyi Huang Dept. of Computer Science, University of Otago Zhiyi Huang (Otago) COSC243 Lecture 16 1 / 24 Overview Last lecture: Hierarchical
More informationECE 650 Systems Programming & Engineering. Spring 2018
ECE 650 Systems Programming & Engineering Spring 2018 User Space / Kernel Interaction Tyler Bletsch Duke University Slides are adapted from Brian Rogers (Duke) Operating System Services User and other
More informationSystem Calls and Signals: Communication with the OS. System Call. strace./hello. Kernel. Context Switch
System Calls and Signals: Communication with the OS Jonathan Misurda jmisurda@cs.pitt.edu System Call An operation (function) that an OS provides for running applications to use CS 1550 2077 strace./hello
More informationMotivation. Threads. Multithreaded Server Architecture. Thread of execution. Chapter 4
Motivation Threads Chapter 4 Most modern applications are multithreaded Threads run within application Multiple tasks with the application can be implemented by separate Update display Fetch data Spell
More informationThread. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University
Operating Systems (Fall/Winter 2018) Thread Yajin Zhou (http://yajin.org) Zhejiang University Acknowledgement: some pages are based on the slides from Zhi Wang(fsu). Review Process Multiple parts: text,
More information4.8 Summary. Practice Exercises
Practice Exercises 191 structures of the parent process. A new task is also created when the clone() system call is made. However, rather than copying all data structures, the new task points to the data
More information!! How is a thread different from a process? !! Why are threads useful? !! How can POSIX threads be useful?
Chapter 2: Threads: Questions CSCI [4 6]730 Operating Systems Threads!! How is a thread different from a process?!! Why are threads useful?!! How can OSIX threads be useful?!! What are user-level and kernel-level
More informationProcess management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)
Process management CSE 451: Operating Systems Spring 2012 Module 4 Processes Ed Lazowska lazowska@cs.washington.edu Allen Center 570 This module begins a series of topics on processes, threads, and synchronization
More information! How is a thread different from a process? ! Why are threads useful? ! How can POSIX threads be useful?
Chapter 2: Threads: Questions CSCI [4 6]730 Operating Systems Threads! How is a thread different from a process?! Why are threads useful?! How can OSIX threads be useful?! What are user-level and kernel-level
More informationCSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476
CSE 451: Operating Systems Winter 2015 Module 4 Processes Mark Zbikowski mzbik@cs.washington.edu Allen Center 476 2013 Gribble, Lazowska, Levy, Zahorjan Process management This module begins a series of
More informationLecture 2 Process Management
Lecture 2 Process Management Process Concept An operating system executes a variety of programs: Batch system jobs Time-shared systems user programs or tasks The terms job and process may be interchangeable
More informationSystem Calls & Signals. CS449 Spring 2016
System Calls & Signals CS449 Spring 2016 Operating system OS a layer of software interposed between the application program and the hardware Application programs Operating system Processor Main memory
More informationCS370 Operating Systems
CS370 Operating Systems Colorado State University Yashwant K Malaiya Spring 2019 Lecture 6 Processes Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Fork( ) causes a branch
More informationCSMC 412. Operating Systems Prof. Ashok K Agrawala Ashok Agrawala Set 4. September 2006 CMSC 412 Set 4
CSMC 412 Operating Systems Prof. Ashok K Agrawala 2005 Ashok Agrawala Set 4 1 Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads 2 Single and
More informationTDIU25: Operating Systems II. Processes, Threads and Scheduling
TDIU25: Operating Systems II. Processes, Threads and Scheduling SGG9: 3.1-3.3, 4.1-4.3, 5.1-5.4 o Process concept: context switch, scheduling queues, creation o Multithreaded programming o Process scheduling
More informationThreads Implementation. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University
Threads Implementation Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Today s Topics How to implement threads? User-level threads Kernel-level
More informationCSE 410: Computer Systems Spring Processes. John Zahorjan Allen Center 534
CSE 410: Computer Systems Spring 2018 Processes John Zahorjan zahorjan@cs.washington.edu Allen Center 534 1. What is a process? Processes 2. What's the process namespace? 3. How are processes represented
More informationExercise (could be a quiz) Solution. Concurrent Programming. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - IV Threads
Exercise (could be a quiz) 1 2 Solution CSE 421/521 - Operating Systems Fall 2013 Lecture - IV Threads Tevfik Koşar 3 University at Buffalo September 12 th, 2013 4 Roadmap Threads Why do we need them?
More informationThreads. CS3026 Operating Systems Lecture 06
Threads CS3026 Operating Systems Lecture 06 Multithreading Multithreading is the ability of an operating system to support multiple threads of execution within a single process Processes have at least
More informationThreads. CS-3013 Operating Systems Hugh C. Lauer. CS-3013, C-Term 2012 Threads 1
Threads CS-3013 Operating Systems Hugh C. Lauer (Slides include materials from Slides include materials from Modern Operating Systems, 3 rd ed., by Andrew Tanenbaum and from Operating System Concepts,
More informationFortran Signal Handling
Fortran Signal Handling Ge Baolai SHARCNET The University of Western Ontario June 19, 2008 1 Signal Handling in User Applications A running programme may be interrupted or terminated by the operating system.
More informationSMD149 - Operating Systems
SMD149 - Operating Systems Roland Parviainen November 3, 2005 1 / 45 Outline Overview 2 / 45 Process (tasks) are necessary for concurrency Instance of a program in execution Next invocation of the program
More informationChapter 1 Introduction
Chapter 1 Introduction Hsung-Pin Chang Department of Computer Science National Chung Hsing University Preference On the basis of 2.4.18 of the Linux kernel www.kernel.org Linux source code is contained
More informationProcess Concept Process in Memory Process State new running waiting ready terminated Diagram of Process State
Process Concept An operating system executes a variety of programs: Batch system jobs Time-shared systems user programs or tasks Textbook uses the terms job and process almost interchangeably Process a
More informationOperating Systems 2010/2011
Operating Systems 2010/2011 Signals Johan Lukkien 1 Signals A signal is a software generated event notification of state change encapsulation of physical event usually: sent from a process to a process
More informationDefinition Multithreading Models Threading Issues Pthreads (Unix)
Chapter 4: Threads Definition Multithreading Models Threading Issues Pthreads (Unix) Solaris 2 Threads Windows 2000 Threads Linux Threads Java Threads 1 Thread A Unix process (heavy-weight process HWP)
More informationOperating Systems. Chapter 4 Threads. Lei Duan
Operating Systems Chapter 4 Threads Lei Duan leiduan@scu.edu.cn 2015.2 Agenda 4.1 Processes and Threads 4.2 Types of Threads 4.3 Multicore and Multithreading 4.4 Summary 2015-04-01 2/49 Agenda 4.1 Processes
More informationLecture 5: Process Description and Control Multithreading Basics in Interprocess communication Introduction to multiprocessors
Lecture 5: Process Description and Control Multithreading Basics in Interprocess communication Introduction to multiprocessors 1 Process:the concept Process = a program in execution Example processes:
More informationChapter 3 Process Description and Control
Operating Systems: Internals and Design Principles Chapter 3 Process Description and Control Seventh Edition By William Stallings Process Control Block Structure of Process Images in Virtual Memory How
More informationLast class: Today: Thread Background. Thread Systems
1 Last class: Thread Background Today: Thread Systems 2 Threading Systems 3 What kind of problems would you solve with threads? Imagine you are building a web server You could allocate a pool of threads,
More informationCHAPTER 2: PROCESS MANAGEMENT
1 CHAPTER 2: PROCESS MANAGEMENT Slides by: Ms. Shree Jaswal TOPICS TO BE COVERED Process description: Process, Process States, Process Control Block (PCB), Threads, Thread management. Process Scheduling:
More informationConcurrency Problems Signals & Synchronization Semaphore Mutual Exclusion Critical Section Monitors
4 Concurrency Concurrency Problems Signals & Synchronization Semaphore Mutual Exclusion Critical Section Monitors 2009 Universität Karlsruhe (TU), System Architecture Group 1 Roadmap for Today Concurrency
More informationThreads. Thread Concept Multithreading Models User & Kernel Threads Pthreads Threads in Solaris, Linux, Windows. 2/13/11 CSE325 - Threads 1
Threads Thread Concept Multithreading Models User & Kernel Threads Pthreads Threads in Solaris, Linux, Windows 2/13/11 CSE325 - Threads 1 Threads The process concept incorporates two abstractions: a virtual
More informationPrinceton University. Computer Science 217: Introduction to Programming Systems. Signals
Princeton University Computer Science 217: Introduction to Programming Systems Signals 1 Goals of this Lecture Help you learn about: Sending signals Handling signals and thereby How the OS exposes the
More informationLecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.
Lecture Topics Today: Threads (Stallings, chapter 4.1-4.3, 4.6) Next: Concurrency (Stallings, chapter 5.1-5.4, 5.7) 1 Announcements Make tutorial Self-Study Exercise #4 Project #2 (due 9/20) Project #3
More information操作系统原理与设计. 第 4 章 Threads( 线程 ) 陈香兰. March 28, 2014 中国科学技术大学计算机学院. 陈香兰 ( 中国科学技术大学计算机学院 ) 操作系统原理与设计 March 28, /
操作系统原理与设计 第 4 章 Threads( 线程 ) 陈香兰 中国科学技术大学计算机学院 March 28, 2014 陈香兰 ( 中国科学技术大学计算机学院 ) 操作系统原理与设计 March 28, 2014 1 / 44 提纲 1 Overview 2 Multithreading Models 3 Thread Libraries 4 Threading Issues 5 OS Examples
More informationPage 1. Analogy: Problems: Operating Systems Lecture 7. Operating Systems Lecture 7
Os-slide#1 /*Sequential Producer & Consumer*/ int i=0; repeat forever Gather material for item i; Produce item i; Use item i; Discard item i; I=I+1; end repeat Analogy: Manufacturing and distribution Print
More informationPart V. Process Management. Sadeghi, Cubaleska RUB Course Operating System Security Memory Management and Protection
Part V Process Management Sadeghi, Cubaleska RUB 2008-09 Course Operating System Security Memory Management and Protection Roadmap of Chapter 5 Notion of Process and Thread Data Structures Used to Manage
More informationLesson 3. The func procedure allows a user to choose the action upon receipt of a signal.
Lesson 3 Signals: When a process terminates abnormally, it usually tries to send a signal indicating what went wrong. C programs can trap these for diagnostics. Software interrupts: Stop executing the
More informationCS420: Operating Systems
Threading Issues James Moscola Department of Engineering & Computer Science York College of Pennsylvania Based on Operating System Concepts, 9th Edition by Silberschatz, Galvin, Gagne Threading Issues
More informationThread Concept. Thread. No. 3. Multiple single-threaded Process. One single-threaded Process. Process vs. Thread. One multi-threaded Process
EECS 3221 Operating System Fundamentals What is thread? Thread Concept No. 3 Thread Difference between a process and a thread Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University
More information