CS420: Operating Systems

Similar documents
Multi-core Programming System Overview

CS420: Operating Systems OS Services & System Calls

Kernel comparison of OpenSolaris, Windows Vista and. Linux 2.6

Operating Systems. 05. Threads. Paul Krzyzanowski. Rutgers University. Spring 2015

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Kernel Types System Calls. Operating Systems. Autumn 2013 CS4023

Chapter 5: CPU Scheduling. Operating System Concepts 8 th Edition

Chapter 6, The Operating System Machine Level

Parallel Computing. Shared memory parallel programming with OpenMP

Operating System: Scheduling

OPERATING SYSTEM SERVICES

Multi-Threading Performance on Commodity Multi-Core Processors

First-class User Level Threads

BLM 413E - Parallel Programming Lecture 3

Operating System Structure

CS3600 SYSTEMS AND NETWORKS

Virtual Real-Time Scheduling

Debugging with TotalView

System Structures. Services Interface Structure

Web Server Architectures

Hybrid Programming with MPI and OpenMP

Lecture 1 Operating System Overview

Virtualization for Cloud Computing

Processes and Non-Preemptive Scheduling. Otto J. Anshus

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

Operating Systems and Networks

Multi-core architectures. Jernej Barbic , Spring 2007 May 3, 2007

Operating Systems. Rafael Ramirez (T, S)

Scalability evaluation of barrier algorithms for OpenMP

CPU Scheduling Outline

Operating System Components

Why Threads Are A Bad Idea (for most purposes)

IBM Software Group. Lotus Domino 6.5 Server Enablement

Parallel Computing. Parallel shared memory computing with OpenMP

Course Development of Programming for General-Purpose Multicore Processors

Basic Concepts in Parallelization

CSE 120 Principles of Operating Systems. Modules, Interfaces, Structure

How To Write A Windows Operating System (Windows) (For Linux) (Windows 2) (Programming) (Operating System) (Permanent) (Powerbook) (Unix) (Amd64) (Win2) (X

Threads Scheduling on Linux Operating Systems

Introducing PgOpenCL A New PostgreSQL Procedural Language Unlocking the Power of the GPU! By Tim Child

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edition

Incorporating Multicore Programming in Bachelor of Science in Computer Engineering Program

This tutorial will take you through step by step approach while learning Operating System concepts.

Scheduling Task Parallelism" on Multi-Socket Multicore Systems"

Section 1.4. Java s Magic: Bytecode, Java Virtual Machine, JIT,

How do Users and Processes interact with the Operating System? Services for Processes. OS Structure with Services. Services for the OS Itself

Resource Containers: A new facility for resource management in server systems

Chapter 2 System Structures

Computer Science 4302 Operating Systems. Student Learning Outcomes

Building Applications Using Micro Focus COBOL

Going Linux on Massive Multicore

Computer Organisation Operating Systems

Operating Systems for Parallel Processing Assistent Lecturer Alecu Felician Economic Informatics Department Academy of Economic Studies Bucharest

Parallel Algorithm Engineering

Automatic Logging of Operating System Effects to Guide Application-Level Architecture Simulation

An examination of the dual-core capability of the new HP xw4300 Workstation

SWARM: A Parallel Programming Framework for Multicore Processors. David A. Bader, Varun N. Kanade and Kamesh Madduri

VMware Server 2.0 Essentials. Virtualization Deployment and Management

CMLOG: A Common Message Logging System

IT304 Experiment 2 To understand the concept of IPC, Pipes, Signals, Multi-Threading and Multiprocessing in the context of networking.

Spring 2011 Prof. Hyesoon Kim

CS222: Systems Programming


Operating System Structures

FAME Operating Systems

Real Time Programming: Concepts

Components of a Computing System. What is an Operating System? Resources. Abstract Resources. Goals of an OS. System Software

Shared Address Space Computing: Programming

What is Multi Core Architecture?

Introduction. System Calls

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

ODROID Multithreading in Android

Workshare Process of Thread Programming and MPI Model on Multicore Architecture

COS 318: Operating Systems

Intro to GPU computing. Spring 2015 Mark Silberstein, , Technion 1

Thomas Fahrig Senior Developer Hypervisor Team. Hypervisor Architecture Terminology Goals Basics Details

Chapter 3: Operating-System Structures. System Components Operating System Services System Calls System Programs System Structure Virtual Machines

Chapter 3 Operating-System Structures

ELEC 377. Operating Systems. Week 1 Class 3

Gildart Haase School of Computer Sciences and Engineering

Parallel Programming Survey

WinBioinfTools: Bioinformatics Tools for Windows Cluster. Done By: Hisham Adel Mohamed

Programming models for heterogeneous computing. Manuel Ujaldón Nvidia CUDA Fellow and A/Prof. Computer Architecture Department University of Malaga

COMP/CS 605: Introduction to Parallel Computing Lecture 21: Shared Memory Programming with OpenMP

Middleware and Distributed Systems. Design of Scalable Servers. Martin v. Löwis. Donnerstag, 16. Februar 12

x64 Servers: Do you want 64 or 32 bit apps with that server?

So#ware Tools and Techniques for HPC, Clouds, and Server- Class SoCs Ron Brightwell

Operating System Software

Introduction to Multicore Programming

Real-time Process Network Sonar Beamformer

CPS221 Lecture: Operating System Structure; Virtual Machines

Operating System Tutorial

Why Choose C/C++ as the programming language? Parallel Programming in C/C++ - OpenMP versus MPI

GPU Parallel Computing Architecture and CUDA Programming Model

Comparison between scheduling algorithms in RTLinux and VxWorks

Introduction to Virtual Machines

The Plan Today... System Calls and API's Basics of OS design Virtual Machines

Operatin g Systems: Internals and Design Principle s. Chapter 10 Multiprocessor and Real-Time Scheduling Seventh Edition By William Stallings

Transcription:

Threads James Moscola Department of Engineering & Computer Science York College of Pennsylvania Based on Operating System Concepts, 9th Edition by Silberschatz, Galvin, Gagne

Threads A thread is a basic unit of processing - Has the following components: Thread ID Program counter Register set Stack - Shares some resources with other threads in same process Code section Data section OS Resources (e.g. open files, signals) Scheduled by the operating system 2

Threads A heavyweight process is a process that has a single thread of control - Can only perform a single task at a time A multi-threaded process is a process that has multiple threads of control - Can perform more than one task at a time Render images Fetch data Update display Check spelling 3

Single and Multithreaded Processes Shared 4

Thread vs Process Processes - - Independent units of execution - Each contains its own state information - Each contains its own address space - Interact with each other through various IPC mechanisms Threads (within the same process) - - Share the same state - Share the same memory space - Share the same variables - Can communicate directly through shared variables - Share signal handling 5

Benefits of Multithreaded Programming Responsiveness - Interactive applications are more responsive when multithreaded (e.g. a thread for the GUI, another for socket, a third for rendering, etc.) Resource Sharing - Unlike processes, threads share memory and resources Economy - Since threads share resources, creating threads and switching between them is more efficient than processes Scalability - Multithreading allows for increased parallelism on multicore systems as each thread can run on a different CPU core 6

Multithreaded Server Architecture 7

Multicore Programming The performance of a process can be increased by properly threading the process to take advantage of modern multicore CPUs Multicore systems have challenges not faced in a single-core/single-threaded environment - Dividing activities - How can an application be divided into separate, concurrent tasks? - Balance - How can those tasks be divided in such a way that each does an equal amount of work? - Data splitting - Can the data for those task be divided for processing on separate CPU cores? - Data dependency - Are there data dependencies between different task? - Testing and debugging - What is the best way to debug a multithreaded program with many different execution paths? 8

Concurrent Execution on a Single-core System Only a single thread can execute at a time Threads are interleaved so each gets time on the processor 9

Parallel Execution on a Multicore System With multiple cores, threads can be divided over the cores and run in parallel May still interleave threads if not enough cores are available for all of the threads 10

Thread Support Threads may be supported at different levels of the OS - User threads Supported above the kernel Managed without kernel support Main user thread libraries currently in use POSIX PThreads / Java threads - Kernel threads Supported by the kernel/operating system Managed by the kernel/operating system Most modern operating systems support kernel threads (e.g. Windows XP/2000, Solaris, Linux, Tru64 UNIX, Mac OS X) 11

Multithreading Models There must be a relationship between user level threads and kernel threads Different models of threading exist to define this relationship - Many-to-One - One-to-One - Many-to-Many 12

Many-to-One Many user-level threads mapped to single kernel thread - Examples: Solaris Green Threads, GNU Portable Threads - Not many systems use this model Thread management is done in user space Entire process will block if any single thread blocks (no other threads will run) Unable to run multiple threads in parallel on a multiprocessor system 13

One-to-One Each user-level thread maps to kernel thread - Examples: Windows NT/XP/2000, Linux, Solaris 9 and later Allows more concurrency - A thread can run when another thread has made a blocking system call - Multiple threads can run in parallel on multiprocessor systems Downside, for each thread created, a corresponding kernel thread must also be created 14

Many-to-Many Model Allows many user level threads to be mapped to many kernel threads - Avoids blocking of threads when a single thread makes a blocking system call Allows the operating system to create a sufficient number of kernel threads Reduces the overhead associated with too many kernel threads as was present in the one-to-one model 15

Two-level Model Similar to the Many-to-Many model except that it allows a user thread to be bound to a specific kernel thread Examples include - IRIX - HP-UX - Tru64 UNIX - Solaris 8 and earlier 16

Thread Libraries A 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 currently in use (1) POSIX PThreads - user-level or kernel-level threads for POSIX-compliant systems (2) Win32 threads - kernel-level threads for Windows systems (3) Java threads 17

POSIX Pthreads May be provided either as user-level or kernel-level A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization 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) 18

Java Threads Java threads are managed by the JVM Typically implemented using the threads model provided by underlying OS Java threads may be created in two different ways: - Extending the Thread class - Implementing the Runnable interface 19

Pthreads Example 20

Pthreads Example (Cont.) 21

Pthreads Code for Joining 10 Threads 22

Win32 API Multithreaded C Program 23

Win32 API Multithreaded C Program (Cont.) 24

Java Multithreaded Program 25

Java Multithreaded Program (Cont.) 26

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 Three methods explored - Thread Pools - OpenMP - Grand Central Dispatch Other methods include Microsoft Threading Building Blocks (TBB), java.util.concurrent package 27

Implicit Threading with OpenMP #include <omp.h> #include <stdio.h> int main(int argc, char *argv[]) { /* standard sequential code here */ /* the next bit is automatically parallelized */ #pragma omp parallel { printf("i am a parallel region."); } #pragma omp parallel for for (int i = 0; i < 1000; i++) { c[i] = a[i] + b[i]; } /* more standard sequential code can go here */ } return 0; 28