Processes & Threads Bahareh Goodarzi. Single & Multiple Thread of control code files data code files data.

Slides:



Advertisements
Similar presentations
1 CSC321 §2 Concurrent Programming Abstraction & Java Threads Section 2 Concurrent Programming Abstraction & Java Threads.
Advertisements

1 Chapter 5 Threads 2 Contents  Overview  Benefits  User and Kernel Threads  Multithreading Models  Solaris 2 Threads  Java Threads.
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.
1Threads What are they? Why are they important? How are they implemented in OSes? How to use threads? (in Java)
Processes CSCI 444/544 Operating Systems Fall 2008.
CS238 Lecture 5 Threads Dr. Alan R. Davis. Threads Definitions Benefits User and Kernel Threads Multithreading Models Solaris 2 Threads Java Threads.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
Threads CSCI 444/544 Operating Systems Fall 2008.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Threads. Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Using Two Queues. Using Multiple Queues Suspended Processes Processor is faster than I/O so all processes could be waiting for I/O Processor is faster.
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.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Parallel Processing (CS526) Spring 2012(Week 8).  Thread Status.  Synchronization in Shared Memory Programming(Java threads ) ◦ Locks ◦ Barriars.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Threads Many software packages are multi-threaded Web browser: one thread display images, another thread retrieves data from the network Word processor:
Implementing Processes and Process Management Brian Bershad.
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Today’s Agenda  Quick Review  Finish Java Threads  The CS Problem Advanced Topics in Software Engineering 1.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
Dr. R R DOCSIT, Dr BAMU. Basic Java : Multi Threading 2 Objectives of This Session State what is Multithreading. Describe the life cycle of Thread.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Thread Scheduling.
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
CPS110: Implementing threads Landon Cox. Recap and looking ahead Hardware OS Applications Where we’ve been Where we’re going.
Java Thread and Memory Model
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Multi-Tasking The Multi-Tasking service is offered by VxWorks with its real- time kernel “WIND”.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Concurrent Computing CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
1 OS Review Processes and Threads Chi Zhang
Managing Processors Jeff Chase Duke University. The story so far: protected CPU mode user mode kernel mode kernel “top half” kernel “bottom half” (interrupt.
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Processes and threads.
Process concept.
Process Management Process Concept Why only the global variables?
OPERATING SYSTEMS CS3502 Fall 2017
Day 12 Threads.
Concurrency, Processes and Threads
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Operating Systems: A Modern Perspective, Chapter 6
Intro to Processes CSSE 332 Operating Systems
Processes in Unix, Linux, and Windows
Threads & multithreading
Processes in Unix, Linux, and Windows
Multithreading.
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Lecture Topics: 11/1 General Operating System Concepts Processes
Threads Chapter 4.
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Still Chapter 2 (Based on Silberchatz’s text and Nachos Roadmap.)
Multithreading in java.
CS510 Operating System Foundations
Process State Model -Compiled by Sheetal for CSIT
Concurrency, Processes and Threads
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
CS Introduction to Operating Systems
Presentation transcript:

Processes & Threads Bahareh Goodarzi

Single & Multiple Thread of control code files data code files data

Process Structure [1]

Process Control Block (PCB)

Diagram of Process State

Thread Structure [1]

The Thread Control Block (TCB) is a structure used to maintain the state of a thread during run-time. It Includes: 1- General-Purpose registers 2- Stacks 3- Program Counter 4- Thread ID Thread Control Block

Diagram of Thread States

Thread States Running: Currently under the CPU control Ready to run: wait the scheduler to given the chance to run. Wait: Voluntarily, give the chance to other thread to run Blocked: wait resources or events to happen.

Thread Creation Extending the Thread class Implementing the Runnable interface

Example 1 class ThreadEx1 extends Thread { private string name, ThreadEx1(String name) { super(name); this.name = name; } public void run() { for (int i = 0; i < 100; i++) { System.out.print(“I am “ + name); }

Example 1 class Test1 { public static void main(String args[]) { ThreadEx1 tr1 = new ThreadEx1 (“alpha"); ThreadEx1 tr2 = new ThreadEx1 (“beta"); tr1.start(); // Start the first thread tr2.start(); // Start the second thread tr1.join(); tr2.join(); }

Example 2 class ThreadEx2 implements Runnable { private String name; ThreadEx2(String name) { this.name = name; } public void run() { for (int i = 0; i < 100; i++) { System.out.print(“I am “ + name); }

class Test2 { public static void main(String args[]) { ThreadEx1 tr1 = new ThreadEx2 (“alpha"); ThreadEx1 tr2 = new ThreadEx2 (“beta"); tr1.start(); // Start the first thread tr2.start(); // Start the second thread tr1.join(); tr2.join(); } Example 2

15 Threads Concept Multiple threads on multiple CPUs Multiple threads sharing a single CPU

Context Switch A context switch (also sometimes referred to as a process switch or a task switch) is the switching of the CPU from one process or thread to another. A context is the contents of a CPU's registers and program counter at any point in time

Steps 1- suspending the progression of one process and storing the CPU's state (i.e., the context) for that process somewhere in memory 2- retrieving the context of the next process from memory and restoring it in the CPU's registers 3- returning to the location indicated by the program counter (i.e., returning to the line of code at which the process was interrupted) in order to resume the process.

18 Thread Scheduling l Two different thread implementations l “Native thread” implementation (e.g. Windows): Performs time-slicing. Interrupts the running thread periodically to give other threads a chance to run. l “Green thread” implementation (e.g. Solaris) Does not perform time-slicing. It keeps a running thread active until a higher-priority thread awakes and takes control.

Native threads vs. Green threads Native threads –Native threads supported directly by the kernel –Every thread can run or block independently –All modern OSs support native threads –Downside: a bit expensive, need to make a crossing into kernel mode to schedule Green Threads: (a lighter version) –User program provides scheduler and thread package –May have several green threads per native thread More economical –Downside: When one thread blocks on I/O, all threads block Kernel cannot adjust scheduling among all threads

20 Sleep() vs. yield() There is a big difference –Calling sleep put the current running thread into the blocked state –Calling yield does not put the calling thread, t1 into the blocked state It merely let the scheduler kick in and pick another thread to run. It might happen that the t1 is select to run again. This happens when t1 has a higher priority than all other runnable threads.

References [1] [2] ttp://rds.yahoo.com/_ylt=A0LEVVRGJipMblUALJ0PxQt.;_ylu=X3oDMTExbzdyNm41BHNlYwNzcgRwb3MDNgRjb2 xvA3JlNAR2dGlkAwRsA1dTMQ-- /SIG=128rnl1c0/EXP= /**http%3A//courses.washington.edu/css430/ppt/Threads.ppt [3] [4] [5] faculty.uscupstate.edu/fli/fall11/scsc511/Slides/03.ppt [6]