SMP threads an Introduction to Posix Threads. Technical Definition 1.Independent stream of instructions that can be scheduled to run by an operating system.

Slides:



Advertisements
Similar presentations
CS Lecture 4 Programming with Posix Threads and Java Threads George Mason University Fall 2009.
Advertisements

CS427 Multicore Architecture and Parallel Computing
Threads Lab اللهم علمنا ما ينفعنا،،، وانفعنا بما علمتنا،،، وزدنا علماً
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
8-1 JMH Associates © 2004, All rights reserved Windows Application Development Chapter 10 - Supplement Introduction to Pthreads for Application Portability.
Lecture 18 Threaded Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
B.Ramamurthy1 POSIX Thread Programming 2/14/97 B.Ramamurthy.
Threads? Threads allow us to have multiple tasks active at the same time in one executable –think of a server handling multiple connections Each thread.
4.7.1 Thread Signal Delivery Two types of signals –Synchronous: Occur as a direct result of program execution Should be delivered to currently executing.
Threads© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science Department.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
CS 241 Section Week #4 (2/19/09). Topics This Section  SMP2 Review  SMP3 Forward  Semaphores  Problems  Recap of Classical Synchronization Problems.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
The University of Adelaide, School of Computer Science
Thread Synchronization with Semaphores
POSIX Threads Programming The following is extracted from a tutorial by Blaise Barney at Livermore Computing Blaise Barney (Lawrence Livermore National.
10/16/ Realizing Concurrency using the thread model B. Ramamurthy.
B. RAMAMURTHY 10/24/ Realizing Concurrency using the thread model.
Operating Systems CMPSC 473 Multi-threading models Tutorial on pthreads Lecture 10: September Instructor: Bhuvan Urgaonkar.
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
Threads and Thread Control Thread Concepts Pthread Creation and Termination Pthread synchronization Threads and Signals.
CS345 Operating Systems Threads Assignment 3. Process vs. Thread process: an address space with 1 or more threads executing within that address space,
POSIX Threads Programming Operating Systems. Processes and Threads In shared memory multiprocessor architectures, such as SMPs, threads can be used to.
What is a thread? process: an address space with 1 or more threads executing within that address space, and the required system resources for those threads.
Includes slides from course CS194 at UC Berkeley, by prof. Katherine Yelick Shared Memory Programming Pthreads: an overview Ing. Andrea Marongiu
Programming with POSIX* Threads Intel Software College.
Pthreads: A shared memory programming model
Threads CSCE Thread Motivation Processes are expensive to create. Context switch between processes is expensive Communication between processes.
1 Pthread Programming CIS450 Winter 2003 Professor Jinhua Guo.
Pthreads.
Discussion Week 2 TA: Kyle Dewey. Overview Concurrency Process level Thread level MIPS - switch.s Project #1.
12/22/ Thread Model for Realizing Concurrency B. Ramamurthy.
Threads A thread is an alternative model of program execution
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.
1 Introduction to Threads Race Conditions. 2 Process Address Space Revisited Code Data OS Stack (a)Process with Single Thread (b) Process with Two 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.
Tutorial 4. In this tutorial session we’ll see Threads.
Realizing Concurrency using the thread model
Chapter 5: Process Synchronization – Part 3
Realizing Concurrency using the thread model
PThreads.
Threads in C Caryl Rahn.
Threads Threads.
Boost String API & Threads
CS399 New Beginnings Jonathan Walpole.
Chapter 4: Threads.
Multithreading Tutorial
Principles of Operating Systems Lecture 8
Multithreading Tutorial
Realizing Concurrency using Posix Threads (pthreads)
Realizing Concurrency using the thread model
Multithreading Tutorial
Realizing Concurrency using the thread model
CSCE 513 Computer Architecture
CS510 Operating System Foundations
Jonathan Walpole Computer Science Portland State University
Chien-Chung Shen CIS/UD
Multithreading Tutorial
Multithreading Tutorial
Concurrency, Processes and Threads
Realizing Concurrency using the thread model
Realizing Concurrency using Posix Threads (pthreads)
Realizing Concurrency using the thread model
Realizing Concurrency using Posix Threads (pthreads)
Tutorial 4.
Shared Memory Programming with Pthreads
POSIX Threads(pthreads)
Presentation transcript:

SMP threads an Introduction to Posix Threads

Technical Definition 1.Independent stream of instructions that can be scheduled to run by an operating system 2.The smallest unit of processing that can be run by an operating system 3.Typically a thread is contained within a process

Shared Memory API's 1.OpenMP o An open source solution to the threaded problem overseen by a board of industry heads o an explicit set of compiler directives which require compiler support o A very programmer friendly API o Less control over execution than other APIs 2.Posix threads o A international standard o A more complicated API base o More control over execution than other APIs 3.Kthreads o Kernel level implementation of threads

Shared Memory Model Threads have their own private data and access to shared memory of other threads in their process.

Structures of SMP Programs

How does Linux Handle Threading? The kernel handles the creation of threads very similar to the way it handles the creation of processes (the clone() function), However the use of specific flags will describe what specific resources are to be shared. This means that processes are also threads and threads are simply a special brand of process tied to another thread. All processes and threads are of the type task_struct

Pthread API 100 different subroutines 9 different prefixes of subroutines o pthread_ o pthread_attr_ o pthread_mutex_ o pthread_mutexattr_ o pthread_cond_ o pthread_condattr_ o pthread_key_ o pthread_rwlock_ o pthread_barrier_

pthread_create( pthread_t *, const pthread_attr_t *, void*(*)(void *), void *); pthread_t * is a pointer to a pthread_t object you allocate to your stack pthread_attr_t is what kind of flags will be set that define how this thread will behave with other threads in the process (passing null is allowed) void*(*)(void *) is the name of a function which will return a void * and has only 1 argument, a void pointer void * is a pointer to a structure of your arguments or a cast of a single argument

pthread_attr_ pthread_attr_t is the data type that will be passed to pthread_create to describe how the pthread should interact with other threads Generally the pthread_attr_t is allocated on the stack and passing the address to your functions is acceptable There are several different flags that can be passed into the this attribute with several different functions. The most useful of these being pthread_attr_init() pthread_attr_setdetachstate() and PTHREAD_CREATE_JOINABLE

Critical Sections Critical Sections of code are defined as: o Code paths that manipulate shared data  This means we must protect our programs from having multiple threads in their critical sections Protecting Critical Sections o Mutexes (Mutual Exclusion) works by accessing a shared mutex which blocks when its already in use and acquires when its not in use o Semaphores work by letting decrementing a counter (atomically) if that would put the semaphore to a negative value it blocks and sleeps the process.

Questions?