CS 284a, 8 October 1997 Copyright (c) 1997-98, John Thornley1 CS 284a Lecture Wednesday, 8 October, 1997.

Slides:



Advertisements
Similar presentations
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Advertisements

CHAPTER 5 THREADS & MULTITHREADING 1. Single and Multithreaded Processes 2.
Chapter 5 Threads os5.
Operating Systems Parallel Systems (Now basic OS knowledge)
Course: Operating Systems Instructor: Umar Kalim NUST Institute of Information Technology, Pakistan Operating Systems.
CS 284a, 7 October 97Copyright (c) , John Thornley1 CS 284a Lecture Tuesday, 7 October 1997.
Operating Systems Parallel Systems and Threads (Soon to be basic OS knowledge)
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Chapter 4: Threads. 2 What’s in a process? A process consists of (at least): –an address space –the code for the running program –the data for the running.
CSE Lecture 15 Introduction to Threads, Synchronization and Mutual Exclusion.
CS238 Lecture 5 Threads Dr. Alan R. Davis. Threads Definitions Benefits User and Kernel Threads Multithreading Models Solaris 2 Threads Java Threads.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
CS444/CS544 Operating Systems Synchronization 2/19/2007 Prof. Searleman
Based on Silberschatz, Galvin and Gagne  2009 Threads Definition and motivation Multithreading Models Threading Issues Examples.
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Chapter 4: Threads.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 4: Threads Dr. Mohamed Hefeeda.
CS 284a, 14 October 1997 Copyright (c) , John Thornley1 CS 284a Lecture Tuesday, 14 October, 1997.
Process Concept An operating system executes a variety of programs
Threads CNS What is a thread?  an independent unit of execution within a process  a "lightweight process"  an independent unit of execution within.
9/13/20151 Threads ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original slides.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Operating System Principles Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
Chapter 4 Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Chapter 4: Multithreaded Programming. 4.2 Multithreaded Programming n Overview n Multithreading Models n Thread Libraries n Threading Issues n Operating.
Chapter 4: Threads. From Processes to Threads 4.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Threads.
Thread. A basic unit of CPU utilization. It comprises a thread ID, a program counter, a register set, and a stack. It is a single sequential flow of control.
Operating Systems Chapter 5 Threads. Benefits Responsiveness Resource Sharing Economy Utilization of MP Architectures.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Threads A thread (or lightweight process) is a basic unit of CPU.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Source: Operating System Concepts by Silberschatz, Galvin and Gagne.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Windows Thread Management
Lecture 5: Threads process as a unit of scheduling and a unit of resource allocation processes vs. threads what to program with threads why use threads.
Shan Gao Fall 2007 Department of Computer Science Georgia State University.
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Department of Computer Science and Software Engineering
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Processes & Threads Introduction to Operating Systems: Module 5.
CS307 Operating Systems Threads Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2011.
Windows CE Overview and Scheduling Presented by Dai Kawano.
Saurav Karmakar. Chapter 4: Threads  Overview  Multithreading Models  Thread Libraries  Threading Issues  Operating System Examples  Windows XP.
Win32 Synchronization CS Spring Overview Kernel Synchronization - Spinlocks Executive Synchronization - Dispatcher Objects Wait Operations.
CSS430 Threads1 Textbook Ch5 These slides were compiled from the OSC textbook slides (Silberschatz, Galvin, and Gagne) and the instructor’s class materials.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
CISC2200 Threads Fall 09. Process  We learn the concept of process  A program in execution  A process owns some resources  A process executes a program.
Contents 1.Overview 2.Multithreading Model 3.Thread Libraries 4.Threading Issues 5.Operating-system Example 2 OS Lab Sun Suk Kim.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
CMSC 421 Spring 2004 Section 0202 Part II: Process Management Chapter 5 Threads.
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
Lecture 5. Example for periority The average waiting time : = 41/5= 8.2.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Threads Overview Benefits, User and Kernel Threads.
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Introduction to threads
Threads Some of these slides were originally made by Dr. Roger deBry. They include text, figures, and information from this class’s textbook, Operating.
Threads & multithreading
Chapter 4: Threads.
Operating System Concepts
Chapter 4: Threads.
ICS 143 Principles of Operating Systems
CSE 410, Spring 2008 Computer Systems
Chapter 05. Multithread.
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Still Chapter 2 (Based on Silberchatz’s text and Nachos Roadmap.)
26.
Window Application Development
Presentation transcript:

CS 284a, 8 October 1997 Copyright (c) , John Thornley1 CS 284a Lecture Wednesday, 8 October, 1997

CS 284a, 8 October 1997 Copyright (c) , John Thornley2 Processes and Threads Process includes address space. Thread is program counter and stack pointer. Process may have many threads. All the threads share the same address space. Processes are heavyweight, threads are lightweight. Processes/threads need not map one-to-one onto processors.

CS 284a, 8 October 1997 Copyright (c) , John Thornley3 Three Threads Within a Process function f function g code data heap PC 1 PC 2 PC 3 stack 1 stack 2 stack 3 SP 1 SP 2 SP 3

CS 284a, 8 October 1997 Copyright (c) , John Thornley4 Thread Execution Model pool of threads pool of processors

CS 284a, 8 October 1997 Copyright (c) , John Thornley5 Thread Execution Model: Key Points Pool of processors, pool of threads. Threads are peers. Dynamic thread creation. Can support many more threads than processors. Threads dynamically switch between processors. Threads share access to memory. Synchronization needed between threads.

CS 284a, 8 October 1997 Copyright (c) , John Thornley6 Why Use Threads? Representing Concurrent Entities –Concurrency is part of the problem specification. –Examples: systems programming and user interfaces. –Single or multiple processors. –This kind of multithreaded programming is difficult. Multiprocessing for Performance –Concurrency is under programmer’s control. –Programs could be written sequentially. –This kind of multithreaded programming should be easier.

CS 284a, 8 October 1997 Copyright (c) , John Thornley7 Commercial Thread Libraries Win32 threads (Windows NT and Windows 95). Pthreads (POSIX Thread Interface). (SGI IRIX, Sun Solaris, HP-UX, IBM AIX, Linux, etc.). Solaris threads (SunOS 5.x). All designed primarily for systems programming.

CS 284a, 8 October 1997 Copyright (c) , John Thornley8 Example: Win32 Threads Thread Management: CreateThread(), SuspendThread(), ResumeThread(), ExitThread(), TerminateThread(), WaitForSingleObject(), WaitForMultipleObjects(), CloseHandle() Critical Sections: InitializeCriticalSection(), DeleteCriticalSection(), EnterCriticalSection(), LeaveCriticalSection() Mutexes: CreateMutex(), OpenMutex(), WaitForSingleObject(), WaitForMultipleObjects(), ReleaseMutex(), CloseHandle() Semaphores: CreateSemaphore(), WaitForSingleObject(), WaitForMultipleObjects() ReleaseSemaphore(), CloseHandle() Events: CreateEvent(), SetEvent(), ResetEvent(), PulseEvent(), WaitForSingleObject(), WaitForMultipleObjects(), CloseHandle() Interlocked Operations: InterlockedIncrement(), InterlockedDecrement(), InterlockedExchange() Thread Priorities: SetThreadPriority(), GetThreadPriority()

CS 284a, 8 October 1997 Copyright (c) , John Thornley9 A Simple Example: Array Summation int array_sum(int n, int data[]) { int mid; int low_sum, high_sum; mid = n/2; low_sum = 0; high_sum = 0; #pragma multithreadable { for (int i = 0; i < mid; i++) low_sum = low_sum + data[i]; for (int j = mid; j < n; j++) high_sum = high_sum + data[j]; } return low_sum + high_sum; }

CS 284a, 8 October 1997 Copyright (c) , John Thornley10 typedef struct { int n, *data, mid; int *high_sum, *low_sum; } args_block; void sum_0(args_block *args) { for (int i = 0; i mid; i++) *args->low_sum = *args->low_sum + args->data[i]; } void sum_1(args_block *args) { for (int j = args->mid; j n; j++) *args->high_sum = *args->high_sum + args->data[j]; } int array_sum(int n, int data[]) { int mid; int low_sum, high_sum; args_block args; HANDLE threads[2]; DWORD thread_ID; mid = n/2; args.n = n; args.data = data; args.mid = mid; args.low_sum = &low_sum; args.high_sum = &high_sum; threads[0] = CreateThread(NULL, 0, sum_0, &args, 0, &thread_ID); threads[1] = CreateThread(NULL, 0, sum_1, &args, 0, &thread_ID); WaitForMultipleObjects(2, threads, TRUE, INFINITE); return low_sum + high_sum; } security attributes stack sizecreation status wait for all

CS 284a, 8 October 1997 Copyright (c) , John Thornley11 The Need for Synchronization Thread 1:... EnterCriticalSection(cs); sum = sum + f(x); LeaveCriticalSection(cs);... Thread 2:... EnterCriticalSection(cs); sum = sum + f(y); LeaveCriticalSection(cs);...

CS 284a, 8 October 1997 Copyright (c) , John Thornley12 Commodity Multithreaded Applications Example Problems: Spreadsheets, CAD/CAM, simulation, video/photo editing and production, games, voice/handwriting recognition, real-time 3D rendering, job scheduling, etc. etc. Need to run as fast as sequential on one processor. Need to run significantly faster on multiprocessors. No recompilation, no relinking, no reconfiguration. Need to adapt dynamically to changing resources. Need to be reliable and timely.

CS 284a, 8 October 1997 Copyright (c) , John Thornley13 The Challenge Ahead The challenge is not shared-memory versus message-passing. The challenge is multiprocessing versus no multiprocessing for commodity applications.

CS 284a, 8 October 1997 Copyright (c) , John Thornley14 An Aside: Automatic Parallelization Write a sequential program. Compiler transforms sequential program into efficient parallel (multithreaded) program (and pigs might fly). A very very very very very very very difficult problem. Decades of work on this problem. Some success with some regular scientific programs. Not a general solution (and probably never will be). Not applicable to large, irregular, dynamic programs.