V 1.0 OE-NIK HP 1 Advanced Programming Fundamentals of parallel execution Processes 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
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process An operating system executes a variety of programs: Batch system.
Operating Systems: Internals and Design Principles
Chapter 14 Multithreading Yingcai Xiao. Multithreading is a mechanism for performing two or more tasks concurrently.  In the managed world of the common.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Threads in C# Threads in C#.
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
Computer Systems/Operating Systems - Class 8
ECE 526 – Network Processing Systems Design Software-based Protocol Processing Chapter 7: D. E. Comer.
Chapter 5 Processes and Threads Copyright © 2008.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.
Processes CSCI 444/544 Operating Systems Fall 2008.
Review: Operating System Manages all system resources ALU Memory I/O Files Objectives: Security Efficiency Convenience.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
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.
Threads Chapter 4. Modern Process & Thread –Process is an infrastructure in which execution takes place  (address space + resources) –Thread is a program.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Chapter 4 Threads, SMP, and Microkernels Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E.
Operating Systems Lecture 09: Threads (Chapter 4)
Advanced Operating Systems CIS 720 Lecture 1. Instructor Dr. Gurdip Singh – 234 Nichols Hall –
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
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.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
Implementing Processes and Process Management Brian Bershad.
1 Threads, SMP, and Microkernels Chapter 4. 2 Focus and Subtopics Focus: More advanced concepts related to process management : Resource ownership vs.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
Processes & Threads Bahareh Goodarzi. Single & Multiple Thread of control code files data code files data.
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 Confidential Enterprise Solutions Group Process and Threads.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Threads G.Anuradha (Reference : William Stallings)
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)
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.
1 Threads, SMP, and Microkernels Chapter Multithreading Operating system supports multiple threads of execution within a single process MS-DOS.
Operating Systems: Internals and Design Principles
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Threads-Process Interaction. CONTENTS  Threads  Process interaction.
Threads. Thread A basic unit of CPU utilization. An Abstract data type representing an independent flow of control within a process A traditional (or.
Multithreading The objectives of this chapter are: To understand the purpose of multithreading To describe Java's multithreading mechanism.
Operating System Concepts
CIS NET Applications1 Chapter 8 – Multithreading and Concurrency Management.
Threads, SMP, and Microkernels Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
Demonstrating Multithreading Concepts. Overvie w Multithreading or free-threading is the ability of an operating system to concurrently run programs that.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Processes and threads.
Thread Fundamentals Header Advanced .NET Threading, Part 1
Lecture Topics: 11/1 Processes Process Management
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Process Management Presented By Aditya Gupta Assistant Professor
Lecture 7 Processes and Threads.
Threads & multithreading
Operating System Concepts
Mid Term review CSC345.
Lecture Topics: 11/1 General Operating System Concepts Processes
Lecture 4- Threads, SMP, and Microkernels
Threads and Concurrency
Threads Chapter 4.
Threads and Concurrency
Foundations and Definitions
Chapter 3: Process Concept
CMSC 202 Threads.
Chapter 3: Process Management
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

V 1.0 OE-NIK HP 1 Advanced Programming Fundamentals of parallel execution Processes Threads

V 1.0 OE-NIK HP 2 Advanced Programming Fundamentals of parallel execution Processes Threads

V 1.0 Fundamentals of parallel execution The Neumann-based computers are executing programs in a purely sequential way To execute multiple programs simultaneously –More than one CPUs / cores –Hyperthreading –Time sharing Number of concurrent operations > number of execution units Separation of “concurrently” executing programs –Processes: high-level separation One program (or a set of resources used by a program task) Separated memory area When faults, only that process is damaged (not the others, nor the OS) No simple way for IntraProcess Communication –Threads: low-level separation Parallelism inside the processes Partially shared memory area for threads in one process 3 OE-NIK HP P 1 process T 11 thread T 12 thread T 13 thread

V 1.0 Time sharing P 1 process Running state Ready or Standby Save state (PCB 2 ) Restore state (PCB 1 ) Save state (PCB 1 ) Restore state (PCB 2 ) Interrupt / system call Running state Ready or Standby P 2 process Interrupt / system call Original image © David A. Solomon and Mark Russinovich 4 OE-NIK HP this figure is generic (DOS/Unix/Windows) and overly simplified; in Windows the base unit of the parallel execution is the thread

V 1.0.NET processes, threads, AppDomain In the.NET framework the processes are equivalents with the OS processes –System.Diagnostics.Process, System.Diagnostics.ProcessStartInfo The.NET threads are (currently) equivalent with the OS threads –It is not limited to this – one OS thread could execute multiple.NET threads In.NET there is an additional level from in-process parallelism, the „application domain” for multiple processes –The managed programs are supervised by the framework, so they cannot affect each other negatively –Thus, there is no need for truly executing some as physically separate processes –Due to speed and memory requirements, it can be advantageous (the creation and maintaining of processes takes up many CPU and memory resources) –Not in our schedule 5 OE-NIK HP

V 1.0 OE-NIK HP 6 Advanced Programming Fundamentals of parallel execution Processes Threads

V 1.0 Processes (fragment) System.Diagnostics.Process class Methods Start() CloseMainWindow()Only with GUI processes Kill() GetCurrentProcess() GetProcesses()List of all processes WaitForExit() Properties StartInfoThe assigned ProcessStartInfo instance PriorityClass EnableRaisingEvents HasExited ExitCode, ExitTime StandardInput, StandardOutput Streams Events Exited 7 OE-NIK HP

V 1.0 Processes (fragment) System.Diagnostics.ProcessStartInfo class Properties FileNameExecutable (on its own or using its associated program) Arguments, WorkingDirectory Domain, UserName, Password RedirectStandardInput, RedirectStandardOutput Redirect the specified stream? ErrorDialogTrue/false, if the execution fails UseShellExecute Use the OS shell execute method (Advantage: more clever execution, independent execution. Disadvantage: cannot read output) Verb Examples of verbs are "Edit", "Open", "OpenAsReadOnly", "Print", and "Printto" WindowStyleInitial window size (minimized, maximized) 8 OE-NIK HP

V 1.0 Example: new process using System; using System.Diagnostics; class Program { static void Main() { Process newProcess = new Process(); newProcess.StartInfo = new ProcessStartInfo("hello.exe", "Joe"); newProcess.StartInfo.ErrorDialog = true; newProcess.StartInfo.UseShellExecute = false; newProcess.StartInfo.RedirectStandardOutput = true; newProcess.Start(); newProcess.WaitForExit(); Console.WriteLine("The messages from the new process:"); Console.Write(newProcess.StandardOutput.ReadToEnd()); Console.ReadLine(); } OE-NIK HP

V 1.0 Exercises Create a console application that executes an arbitrary number of traceroute (tracert) processes so the individual calls do not block the main application Use the netstat command’s output to list the currently opened network communication channels for an arbitrary process 10 OE-NIK HP

V 1.0 OE-NIK HP 11 Advanced Programming Fundamentals of parallel execution Processes Threads

V 1.0 Single threading / Multi threading? Multi-threading is essential for the responsiveness of the program / OS, but... It is expensive (depending on the OS) Memory allocated for each thread: –Stack, thread context (stb.) Wasted CPU time: –Management of the time sharing Ideally: number of active threads = number of cores –Context changes  Increased number of “cache miss” events There are lots of context changes, lots of cache miss events... –Every managed DLL is notified when creating/destroying a thread Dll_Main(DLL_THREAD_ATTACH), Dll_Main(DLL_THREAD_DETACH) calls powerpnt.exe 147 dll!!!!... VS 2012: 183 dll... Still: Thread overhead < process overhead, especially in Windows OS OE-NIK HP 12

V 1.0 Possibilities for multi-threaded processing Asynchronous method call (not in our schedule) –We can call delegates and special methods supporting this pattern Thread class –Low-level management of threads –Simple (simply “execute this method in another thread”), but requires lots of accuracy and planning (Concurrency? Return values?) ThreadPool class (not in our schedule) –There is a set/pool of threads waiting for usage –No need for individually creating/destroying threads –Simple and very efficient, but lacks functionality (e.g. thread identification) BackgroundWorker class (not in our schedule) –Typically used to separate the UI thread from long operations –Very limited functionality TPL / Task class –High-level thread management, unified API with high functionality TPL / Parallel class –Data-parallel execution, Parallel loops 13 OE-NIK HP

V 1.0 Threads (fragment) System.Threading.Thread class Methods Start() Suspend(), Resume() Abort()Rarely used GetHashCode()Usable for identification Sleep()Wait a given timespan Join()Wait for a thread to finish Properties CurrentCulture, CurrentUICulture IsBackground The execution of a program is finished when the last foreground thread is finished (the background threads are aborted) IsThreadPoolThread ManagedThreadID Name Priority ThreadState 14 OE-NIK HP

V 1.0 System.Threading.Thread example using System; using System.Threading; class Program { static void Main(string[] args) { Console.WriteLine("Now we create a thread"); Console.WriteLine("Main thread ({0})", Thread.CurrentThread.GetHashCode()); Thread newThread = new Thread(ThreadMethod); newThread.Name = "NewThread"; newThread.Start(); newThread.Join(); } static void ThreadMethod() { Console.WriteLine("{0} (ID: {1})", Thread.CurrentThread.Name, Thread.CurrentThread.GetHashCode()); } OE-NIK HP

V 1.0 Exercise Create a console application that is capable of measuring the speed of a webpage throughout 10 seconds by executing System.Net.WebClient().DownloadString(url) calls in separate threads Create a console application that is capable of concurrently downloading several RSS feeds and looking for user-specified keywords in them. 16 OE-NIK HP