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.

Slides:



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

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.
Pthreads & Concurrency. Acknowledgements  The material in this tutorial is based in part on: POSIX Threads Programming, by Blaise Barney.
Professor: Shu-Ching Chen TA: Hsin-Yu Ha.  An independent stream of instructions that can be scheduled to run  A path of execution int a, b; int c;
PTHREADS These notes are from LLNL Pthreads Tutorial
Computer Architecture II 1 Computer architecture II Programming: POSIX Threads OpenMP.
Fork Fork is used to create a child process. Most network servers under Unix are written this way Concurrent server: parent accepts the connection, forks.
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.
Threads© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science Department.
PRINCIPLES OF OPERATING SYSTEMS Lecture 6: Processes CPSC 457, Spring 2015 May 21, 2015 M. Reza Zakerinasab Department of Computer Science, University.
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
10/16/ Realizing Concurrency using the thread model B. Ramamurthy.
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.
Operating Systems CMPSC 473 Multi-threading models Tutorial on pthreads Lecture 10: September Instructor: Bhuvan Urgaonkar.
June-Hyun, Moon Computer Communications LAB., Kwangwoon University Chapter 26 - Threads.
Multi-threaded Programming with POSIX Threads CSE331 Operating Systems Design.
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.
1 Threads Chapter 11 from the book: Inter-process Communications in Linux: The Nooks & Crannies by John Shapley Gray Publisher: Prentice Hall Pub Date:
CS333 Intro to Operating Systems Jonathan Walpole.
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.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Unix System Calls and Posix Threads.
12/22/ Thread Model for Realizing Concurrency B. Ramamurthy.
Chapter 6 P-Threads. Names The naming convention for a method/function/operation is: – pthread_thing_operation(..) – Where thing is the object used (such.
Unix Internals Concurrent Programming. Unix Processes Processes contain information about program resources and program execution state, including: Process.
Copyright ©: Nahrstedt, Angrave, Abdelzaher
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.
PRINCIPLES OF OPERATING SYSTEMS Tutorial-4: Multi-process and Multi-threaded Programming CPSC 457, Spring 2015 May 28/29, 2015 Department of Computer Science,
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.
A thread is a basic unit of CPU utilization within a process Each thread has its own – thread ID – program counter – register set – stack It shares the.
Realizing Concurrency using the thread model
Threads Some of these slides were originally made by Dr. Roger deBry. They include text, figures, and information from this class’s textbook, Operating.
Realizing Concurrency using the thread model
Shared-Memory Programming with Threads
Threads Threads.
Boost String API & Threads
Copyright ©: Nahrstedt, Angrave, Abdelzaher
Thread Programming.
PTHREADS These notes are from LLNL Pthreads Tutorial
Multithreading Tutorial
Principles of Operating Systems Lecture 8
Multithreading Tutorial
Realizing Concurrency using Posix Threads (pthreads)
Realizing Concurrency using the thread model
PTHREADS AND SEMAPHORES
Multithreading Tutorial
Thread Programming.
Realizing Concurrency using the thread model
Pthread Prof. Ikjun Yeom TA – Mugyo
Operating System Concepts
Multithreading Tutorial
Multithreading Tutorial
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:

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 c; a = 1; b = a + 2; c = 3; Sequentially execute int a, b; a = 1; b = a + 2; int c; c = 5; CPU Multi-Thread Single-Thread CPU

 Program  An execution file stored in the hard drive  Process  An execution file stored in the Memory  Thread  An execution path of part of the process HDD Memory ProgramProcessThread

 Parallel execution  Shared resources  Easier to create and destroy than processes (100X)  Easy porting to multiple CPUs

 Standardized C language threads programming interface for UNIX systems  Four major groups  Thread management: Routines that work directly on threads - creating, detaching, joining, etc.  Mutex: Routines that deal with synchronization. Mutex functions provide for creating, destroying, locking and unlocking mutexes.  Condition variable: Routines that address communications between threads that share a mutex.  Synchronization: Routines that manage read/write locks and barriers.

 pthread_create() Return 0 if OK, nonzero on error  Four Arguments ▪ Thread : A thread identifier ▪ Attr : A pointer to a thread attribute object ▪ Start_routine : A pointer to the function the thread executes ▪ Arg : The argument to the function

 Single variable

 Several variables

 pthread_exit() Return 0 if OK, nonzero on error  Four ways of terminating a thread  The thread returns from its starting routine  The thread makes a call to the pthread_exit subroutine  The thread is canceled by another thread  The entire process is terminated  If main() finishes first, without calling pthread_exit

 Example of pthread_exit()

 pthread_join() Return 0 if OK, nonzero on error  Wait from other threads to terminate by calling it

 pthread_self()  It returns the unique, system assigned thread ID of the calling thread  pthread_detach() Return 0 if OK, nonzero on error  It can be used to explicitly detach a thread

 Join  Mutexes  Condition variables

 Mutexes are used  to prevent data inconsistencies due to operations by multiple threads upon the same memory area performed at the same time  to prevent race conditions where an order of operation upon the memory is expected

 Condition variables are used  to allow threads to synchronize based upon the actual value of data without continually polling to check whether the condition if met  in conjunction with a mutex lock

 POSIX Threads Programming   Pthreads primer  er.html er.html  POSIX thread (pthread) Tutorial  alPosixThreads.html alPosixThreads.html