CS 838: Pervasive Parallelism Introduction to pthreads Copyright 2005 Mark D. Hill University of Wisconsin-Madison Slides are derived from online references.

Slides:



Advertisements
Similar presentations
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process An operating system executes a variety of programs: Batch system.
Advertisements

Go Language * Go - Routines * Channels. New Concepts Do not communicate by sharing memory; instead, share memory by communicating. creating shared memory.
Threads. What do we have so far The basic unit of CPU utilization is a process. To run a program (a sequence of code), create a process. Processes are.
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
Chapter 5 Processes and Threads Copyright © 2008.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
3.5 Interprocess Communication
Threads CSCI 444/544 Operating Systems Fall 2008.
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Inter-Process Communication  most OSs provide several abstractions for inter- process communication: message passing, shared memory, etc.  communication.
Lecture 4: Parallel Programming Models. Parallel Programming Models Parallel Programming Models: Data parallelism / Task parallelism Explicit parallelism.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Threads, Thread management & Resource Management.
Operating System Concepts Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
10/16/ Realizing Concurrency using the thread model B. Ramamurthy.
CS 838: Pervasive Parallelism Introduction to OpenMP Copyright 2005 Mark D. Hill University of Wisconsin-Madison Slides are derived from online references.
Today’s topic Pthread Some materials and figures are obtained from the POSIX threads Programming tutorial at
B. RAMAMURTHY 10/24/ Realizing Concurrency using the thread model.
June-Hyun, Moon Computer Communications LAB., Kwangwoon University Chapter 26 - Threads.
Threads and Thread Control Thread Concepts Pthread Creation and Termination Pthread synchronization Threads and Signals.
POSIX Threads Programming Operating Systems. Processes and Threads In shared memory multiprocessor architectures, such as SMPs, threads can be used to.
Includes slides from course CS194 at UC Berkeley, by prof. Katherine Yelick Shared Memory Programming Pthreads: an overview Ing. Andrea Marongiu
Source: Operating System Concepts by Silberschatz, Galvin and Gagne.
CS333 Intro to Operating Systems Jonathan Walpole.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Professor: Shu-Ching Chen TA: Samira Pouyanfar.  An independent stream of instructions that can be scheduled to run  A path of execution int a, b; int.
Introduction to OpenMP Eric Aubanel Advanced Computational Research Laboratory Faculty of Computer Science, UNB Fredericton, New Brunswick.
Consider Letting inetd Launch Your Application. inetd daemon  Problems starting with /etc/rc(without inet daemon)  All the servers contains nearly identical.
Department of Computer Science and Software Engineering
12/22/ Thread Model for Realizing Concurrency B. Ramamurthy.
CS307 Operating Systems Threads Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2011.
Threads, Thread management & Resource Management.
Threads-Process Interaction. CONTENTS  Threads  Process interaction.
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
NCHU System & Network Lab Lab #6 Thread Management Operating System Lab.
SMP Basics KeyStone Training Multicore Applications Literature Number: SPRPxxx 1.
Thread Basic Thread operations include thread creation, termination, synchronization, data management Threads in the same process share:  Process address.
Processes Chapter 3. Processes in Distributed Systems Processes and threads –Introduction to threads –Distinction between threads and processes Threads.
B. RAMAMURTHY 5/10/2013 Amrita-UB-MSES Realizing Concurrency using the thread model.
7/9/ Realizing Concurrency using Posix Threads (pthreads) B. Ramamurthy.
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
Chapter 4 – Thread Concepts
Realizing Concurrency using the thread model
Realizing Concurrency using the thread model
Protection of System Resources
Chapter 4 – Thread Concepts
Threads in C Caryl Rahn.
CS399 New Beginnings Jonathan Walpole.
Multithreading Tutorial
Chapter 4 Threads.
Threads and Cooperation
Realizing Concurrency using Posix Threads (pthreads)
Realizing Concurrency using the thread model
Multithreading Tutorial
Realizing Concurrency using the thread model
Threads and Concurrency
Multithreading Tutorial
Programming with Shared Memory
Jonathan Walpole Computer Science Portland State University
Multithreading Tutorial
Realizing Concurrency using the thread model
Realizing Concurrency using Posix Threads (pthreads)
Realizing Concurrency using the thread model
Programming with Shared Memory
Realizing Concurrency using Posix Threads (pthreads)
CS510 Operating System Foundations
CS Introduction to Operating Systems
Presentation transcript:

CS 838: Pervasive Parallelism Introduction to pthreads Copyright 2005 Mark D. Hill University of Wisconsin-Madison Slides are derived from online references from Lawrence Livermore National Laboratory as well as CS 757 notes created by Mark Hill and Min Xu Thanks!

2 (C) 2005 CS 838 Outline Programming Model –Threaded Model –Threads Overview –pthreads Syntax by Example –Expressing parallelism –Synchronization

3 (C) 2005 CS 838 Parallel Programming (Review) Multiple instruction streams working cooperatively at the same time Components –Communication –Synchronization

4 (C) 2005 CS 838 MPI (Review) Per-processor private address space Communication –Explicit –Pass messages Synchronization –Implicit –Message receive

5 (C) 2005 CS 838 Contrast with pthreads Shared memory: single, shared address space Communication –Implicit –A write to a shared address by any thread is immediately visible to all threads Synchronization –Explicit –Why?

6 (C) 2005 CS 838 Races Example –Initial value of a = 0 –T1: a = 1 –T2: a = 2 –T3: printf(“%d”, a); –Output: ??? Strategies to combat (details soon) –Locks (mutexes) –Condition variables (CVs) –Barriers

7 (C) 2005 CS 838 Outline Programming Model –Threaded Model –Threads Overview –pthreads Syntax by Example –Expressing parallelism –Synchronization

8 (C) 2005 CS 838 Thread Stream of instructions that OS can schedule to run independently Think of procedure that runs independently from / concurrently with main program Lets you run many procedures (even many incarnations of the same one) at the same time Each one has its own, independent control flow

9 (C) 2005 CS 838 System View Unix process –Created by OS with a fair amount of overhead –Contains info about program resources & execution state »pid, gid, uid, environment, working dir, instructions, registers, stack, heap, file descriptor, signal actions, shared libraries, IPC tools… Threads –Multiple can belong to the same Unix process –All share process resources –Lightweight »Only duplicate enough state to run independently: Stack pointer, registers, scheduling properties, pending & blocked signals, thread-specific data

10 (C) 2005 CS 838 Process vs. Thread Courtesy of Lawrence Livermore National Lab

11 (C) 2005 CS 838 Outline Programming Model –Threaded Model –Threads Overview –pthreads Syntax by Example –Expressing parallelism –Synchronization

12 (C) 2005 CS 838 pthreads Posix threads IEEE POSIX c standard Implemented via a library Portable to many systems

13 (C) 2005 CS 838 Outline Programming Model –Threaded Model –Threads Overview –pthreads Syntax by Example –Expressing parallelism –Synchronization

14 (C) 2005 CS 838 Barrier With Sense Reversal BARRIER(bar_name, p) { /* toggle private state */ local_sense = !(local_sense); LOCK(bar_name.lock); bar_name.counter++; UNLOCK(bar_name.lock); if (bar_name.counter == p) { bar_name.counter = 0; bar_name.flag = local_sense; } else { /* busy wait */ while(bar_name.flag != local_sense) {}; }

15 (C) 2005 CS 838 Summary pthreads is a library for threaded programming Write programs with pthreads –#include –man pthreads for a list of functions »Thread creation »Synchronization Lock / mutex Condition variable Barrier »Thread termination –Compile: cc –mt –lpthread program.c Review example in eg_pthread.tar.gz