© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

Threads, SMP, and Microkernels
Chapter 5 Threads os5.
Day 10 Threads. Threads and Processes  Process is seen as two entities Unit of resource allocation (process or task) Unit of dispatch or scheduling (thread.
Threads Irfan Khan Myo Thein What Are Threads ? a light, fine, string like length of material made up of two or more fibers or strands of spun cotton,
Chapter 4: Multithreaded Programming
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 5: Threads 9/29/03+ Overview Benefits User and Kernel Threads Multithreading.
Threads - Definition - Advantages using Threads - User and Kernel Threads - Multithreading Models - Java and Solaris Threads - Examples - Definition -
CS238 Lecture 5 Threads Dr. Alan R. Davis. Threads Definitions Benefits User and Kernel Threads Multithreading Models Solaris 2 Threads Java Threads.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Based on Silberschatz, Galvin and Gagne  2009 Threads Definition and motivation Multithreading Models Threading Issues Examples.
Threads CSCI 444/544 Operating Systems Fall 2008.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Threads. Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics.
Process Concept An operating system executes a variety of programs
A. Frank - P. Weisberg Operating Systems Threads Implementation.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
ThreadsThreads operating systems. ThreadsThreads A Thread, or thread of execution, is the sequence of instructions being executed. A process may have.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Processes Part I Processes & Threads* *Referred to slides by Dr. Sanjeev Setia at George Mason University Chapter 3.
Chapter 4 Threads, SMP, and Microkernels Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
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.
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Threads, SMP, and Microkernels Chapter 4. 2 Outline n Threads n Symmetric Multiprocessing (SMP) n Microkernel n Linux Threads.
Threads, Thread management & Resource Management.
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership: process includes a virtual address space to hold the process image (fig 3.16)
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
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.
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts What is Thread “Thread is a part of a program.
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
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Processes & Threads Introduction to Operating Systems: Module 5.
1 OS Review Processes and Threads Chi Zhang
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
Chapter 4 – Thread Concepts
OPERATING SYSTEM CONCEPT AND PRACTISE
CS 6560: Operating Systems Design
Concurrency, Processes and Threads
Chapter 4 – Thread Concepts
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 5: Threads Overview Multithreading Models Threading Issues
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 4 Threads.
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 4: Threads.
Chapter 4: Threads.
Threads Chapter 4.
Chapter 4: Threads.
Concurrency, Processes and Threads
Chapter 4: Threads.
Chapter 5: Threads Overview Multithreading Models Threading Issues
CS510 Operating System Foundations
Concurrency, Processes and Threads
Chapter 4: Threads.
Chapter 4: Threads.
Presentation transcript:

© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads

© 2004, D. J. Foreman 2-2 Concurrency  The appearance that multiple actions are occurring at the same time  On a uni-processor, something must make that happen ■ A collaboration between the OS and the hardware  On a multi-processor, the same problems exist (for each CPU) as on a uni-processor

© 2004, D. J. Foreman 2-3  Combines multiplexing types:  Space-multiplexing - Physical Memory  Time-multiplexing - Physical Processor Multiprogramming Process 0 Process 1 Process n …

© 2004, D. J. Foreman 2-4 Multiprogramming-2  Multiprogramming ■ N programs apparently running simultaneously space-multiplexed in executable memory time-multiplexed across the central processor  Reason why desired ■ Greater throughput (work done per unit time) ■ More work occurring at the same time  Resources required ■ CPU ■ Memory

© 2004, D. J. Foreman 2-5 The CPU  Instruction cycles ■ Access memory and/or registers ■ Sequential flow via "instruction register" ■ One instruction-completion at a time (Pipelines only increase the # of completions per time unit). They are still sequential!  Modes of execution ■ Privileged (System) ■ Non-privileged (User )

Context Switching  4 atomic actions, depending on direction  Kernel to user ■ Memory protection on ■ Privilege mode off ■ Interrupts on (allowed) ■ Set instruction counter  User to kernel ■ Memory protection off ■ Privilege mode on ■ Interrupts off (NOT allowed) ■ Save instruction counter © 2004, D. J. Foreman 2-6

© 2004, D. J. Foreman 2-7 Memory  Sequential addressing (0 – n)  Partitioned ■ System Inaccessible by user programs ■ User Partitioned for multiple users Accessible by system programs

© 2004, D. J. Foreman 2-8 Processes-1  A Process is ■ A running program & its address space ■ A unit of resource management ■ Independent of other processes NO sharing of memory with other processes May share files open at Fork time  One program may start multiple processes, each in its own address space

© 2004, D. J. Foreman 2-9 Operating System Processes-2 Abstraction Process-1Process-n Memory CPU Instruction stream Data stream

© 2004, D. J. Foreman 2-10 Process & Address Space Address Space Code Resources Abstract Machine Environment Stack Data Resources

© 2004, D. J. Foreman 2-11 Processes-3  The Process life-cycle ■ Creation User or scheduled system activation ■ Execution Running – Performing instructions (using the ALU) Waiting – Resources or Signals Ready – All resources available except memory and ALU ■ Termination Process is no longer available

© 2004, D. J. Foreman 2-12 Processes-4  Space multiplexing ■ Each process operates in its own "address space" ■ Address space is a sequence of memory locations (addresses) from 0 to 'n' as seen by the application ■ Process addresses must be "mapped" to real addresses in the real machine  More on this later

© 2004, D. J. Foreman 2-13 Processes-5  Time multiplexing ■ Each process is given a small portion of time to perform instructions ■ O/S controls the time per process and which process gets control next Many algorithms for this No rules (from user's/programmer's view) on which process will run next or for how long Some OS's dynamically adjust both time and sequence

© 2004, D. J. Foreman 2-14 Processes-7  FORK (label) ■ Starts a process running from the labeled instruction – gets a copy of address space  QUIT() ■ Process terminates itself  JOIN (count) (an atomic operation) ■ Merges >=2 processes ■ Really more like "quit, unless I'm the only process left"

© 2004, D. J. Foreman 2-15 Threads-1  A unit of execution within a process (like a lightweight process – an "lwp") also called a "task"  Share address space, data and devices with other threads within the process  Private stack, status (IC, state, etc)  Multi-threading ■ >1 thread per process  Limited by system to some max # ■ Per system ■ Per process

© 2004, D. J. Foreman 2-16 Thread Models DOS JRE Classic UNIX WinXX, Solaris, Linux, OS/2

© 2004, D. J. Foreman 2-17 Threads-2  Several thread API's ■ Solaris: kernel-level threads & pthreads ■ Windows: kernel-level threads & pthreads ■ OS/2: kernel-level threads ■ Posix (pthreads) – full set of functions #include // for C, C++ Allows porting without re-coding ■ Java threads implemented in JVM, independent of OS support Like multiprogramming implementation in Win3.1 Uses underlying kernel support where available

© 2004, D. J. Foreman 2-18 Threads-3  Windows (native) ■ CreateThread( DWORD dwCreateFlags = 0, UINT nStackSize = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );  POSIX (Linux, Solaris, Windows) ■ iret1 = pthread_create( &thread1, NULL, (void*)&print_message_function, (void*) message1);

© 2004, D. J. Foreman 2-19 Threads-4  Advantages of kernel-supported threads: ■ May request resources with or without blocking on the request ■ Blocked thread does NOT block other threads ■ Inexpensive context switch ■ Utilize MP architecture  Thread library for user threads is in user space ■ Thread library schedules user threads onto LWP’s ■ LWP’s are: implemented by kernel threads scheduled by the kernel.

© 2004, D. J. Foreman 2-20 Notes on Java  The JVM ■ uses monitors for mutual exclusion ■ provides wait and notify for cooperation

© 2004, D. J. Foreman 2-21 Java & Threads-1  Thread creation – 2 ways 1. import java.lang.*; public class Counter extends Thread { public void run() //overrides Thread.run {.... } } extension from the Thread class

© 2004, D. J. Foreman 2-22 Java & Threads-2 2. import java.lang.*; public class Counter implements Runnable { Thread T; public void run() {.... } } ■ Instance of the Thread class as a variable of the Counter class – creates an interface ■ Can still extend the Counter class

© 2004, D. J. Foreman 2-23 Java & Threads-3  Difference between the two methods ■ Implementing Runnable, -> greater flexibility in the creation of the class counter  Thread class also implements the Runnable interface

© 2004, D. J. Foreman 2-24 Wait & Signal - semaphores  Classical definitions ■ Wait - P (s) // make me wait for something DO WHILE (s<=0) END s=s-1 // when s becomes > 0, decrement it ■ Signal - V (s) // tell others: my critical job is done s=s+1  These MUST appear as ATOMIC operations to the application