CIS 330 -.NET Applications1 Chapter 8 – Multithreading and Concurrency Management.

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

How to Build Multi- threaded Applications in.NET Mazen S. Alzogbi Technology Specialist Microsoft Corporation.
Ade Azurat, Advanced Programming 2004 (Based on LYS Stefanus’s slides) Advanced Programming 2004, Based on LYS Stefanus’s slides Slide 2.1 Multithreading.
Chapter 14 Multithreading Yingcai Xiao. Multithreading is a mechanism for performing two or more tasks concurrently.  In the managed world of the common.
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Intro to OS CUCS Mossé Processes and Threads What is a process? What is a thread? What types? A program has one or more locus of execution. Each execution.
Overview of Threading with the.NET Framework  Wallace B. McClure  Scalable Development, Inc. Scalable Development, Inc. Building systems today that perform.
Lecture 5 : JAVA Thread Programming Courtesy : MIT Prof. Amarasinghe and Dr. Rabbah’s course note.
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.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
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.
111 © 2002, Cisco Systems, Inc. All rights reserved.
1 Confidential Enterprise Solutions Group Process 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.NETConcurrent programmingNOEA / PQC 2007 Concurrent programming Threads –Introduction –Synchronization.
Threads G.Anuradha (Reference : William Stallings)
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
1 Threads, SMP, and Microkernels Chapter Multithreading Operating system supports multiple threads of execution within a single process MS-DOS.
Upcoming Presentations ILM Professional Service – Proprietary and Confidential ( DateTimeTopicPresenter March PM Distributed.
In Java processes are called threads. Additional threads are associated with objects. An application is associated with an initial thread via a static.
15.1 Threads and Multi- threading Understanding threads and multi-threading In general, modern computers perform one task at a time It is often.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# 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.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Lecture 20 Threads Richard Gesick. Threads Makes use of multiple processors/cores if available Share memory within the program (as opposed to processes.
Internet Computing Module II. Threads – Multithreaded programs, thread Priorities and Thread Synchronization.
3/12/2013Computer Engg, IIT(BHU)1 OpenMP-1. OpenMP is a portable, multiprocessing API for shared memory computers OpenMP is not a “language” Instead,
1 Critical Section Problem CIS 450 Winter 2003 Professor Jinhua Guo.
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
V 1.0 OE-NIK HP 1 Advanced Programming Fundamentals of parallel execution Processes Threads.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Threads Some of these slides were originally made by Dr. Roger deBry. They include text, figures, and information from this class’s textbook, Operating.
Segments Introduction: slides minutes
Threading Lecture 11 M. Ipalakova.
Processes and threads.
Java Multithreading.
Background on the need for Synchronization
Thread Fundamentals Header Advanced .NET Threading, Part 1
Multithreaded Programming in Java
Multithreading Tutorial
Other Important Synchronization Primitives
Computer Engg, IIT(BHU)
Lecture 21 Concurrency Introduction
Jim Fawcett CSE681 – Software Modeling and Analysis Fall 2005
Threads and Locks.
Threads & multithreading
Multithreading.
Multithreading Tutorial
Java Based Techhnology
Multithreading.
Threading using C# and .Net
Multithreaded Programming
Threads and Concurrency
Multithreaded Programming
Multithread Programming
Multithreading Tutorial
Multithreading Tutorial
Multithreading in java.
CS510 Operating System Foundations
Lecture 19 Threads CSE /6/2019.
CSE 153 Design of Operating Systems Winter 2019
Chapter 3: Process Management
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

CIS NET Applications1 Chapter 8 – Multithreading and Concurrency Management

CIS NET Applications2 Objectives Threads.Net Thread Class Thread Blocking Synchronizing Threads.Net Synchronizing Options

CIS NET Applications3 Threads Thread: path of execution within a process Every application runs on at least one thread Applications use Two kinds of operations: –CPU-bound –I/O-bound CPU-bound operation threads more advantageous on multi- processor machines I/O-bound operation threads often ran concurrently with CPU-bound ones Multithreading: Can improve Application throughput and performance Most User Interfaces run on separate threads

CIS NET Applications4 Threads (cont) Each Thread is allocated –registers –program counter –a stack and a stack pointer –is assigned a time slot and a priority Operating System manages –thread scheduling –context switches –thread-manipulation requests (start, sleep, etc.)

CIS NET Applications5.NET Thread Class Defined in System.Threading namespace Some Properties: –CurrentThread : static property that returns an instance of the current managed thread –ManagedThreadId : returns unique thread id –Name : string property that can be set and used by developers

CIS NET Applications6 Spinning off a new thread using System.Threading; Public class MyClass { Thread currentThread = Thread.CurrentThread; string caption = “Thread ID = “; caption += currentThread.ManagedThreadId; MessageBox.Show(“ShowMessage runs on new thread”,caption); } MyClass obj = new MyClass(); Thread workerThread = new Thread(obj.ShowMessage); workerThread.Start();

CIS NET Applications7 Thread Blocking Suspend(); Resume(); Sleep(int millisecondsTimeout); Sleep(TimeSpan timeout); SpinWait(int iterations); Join(); overloaded with int or TimeSpan parameters Interrupt(); Abort(); None of the above are really recommended – recommend use of.NET synchronization objects Race Condition: when one thread must wait for another thread to complete before proceeding

CIS NET Applications8 Threads (cont) Threads know their state through the ThreadState enumerated type property (Aborted, Running, Stopped, etc.) Foreground and Background Threads –When all foreground thread processes have exited, the application closes Thread Priority and Scheduling –Should mess with priorities –Scheduling is preemptive

CIS NET Applications9 Synchronizing Threads In multithreaded applications you must synchronize access to objects by concurrent multiple threads All components must be thread-safe: uses mechanisms to prevent multiple threads from simultaneously accessing its methods and corrupting its state. Deadlock: when two threads simultaneously attempt to access each other’s tread-safe resource Writing robust, high-performance multithreaded code requires a great deal of skill and discipline

CIS NET Applications10 Synchronization with.NET Automatic Synchronization –Use the [Synchronization] attribute for whole components –Based on the.NET architecture that organized components within separate Processes, App Domains, Contexts, and Synchronization domains. See page 204 and 206. –Easy to use Manual Synchronization –Uses rich set of synchronization locks (monitors, events, mutexes, semaphores, and interlocks) –Fine-grained control over what is locked (objects, members, or single line of code) –Requires careful design to limit deadlocks, state corruption, and race conditions

CIS NET Applications11 Summary Threads.Net Thread Class Thread Blocking Synchronizing Threads.Net Synchronizing Options