This document discusses multitasking and multithreading in Java. It defines key concepts like processes, process control blocks, multitasking, and multithreading. Specifically, it states that a process is an instance of a running program, processes have separate memory spaces but threads within the same process share memory and can corrupt each other's data. It also notes that context switching is more expensive for processes than threads.
This document discusses multitasking and multithreading in Java. It defines key concepts like processes, process control blocks, multitasking, and multithreading. Specifically, it states that a process is an instance of a running program, processes have separate memory spaces but threads within the same process share memory and can corrupt each other's data. It also notes that context switching is more expensive for processes than threads.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10
Object-Oriented Programming (CS F213)
Module VI: Multithreading in Java
CS F213 RL 14.1: Multitasking and Multithreading (Introduction)
BITS Pilani Dr. Pankaj Vyas
Department of Computer Science, BITS-Pilani, Pilani Campus CS F213 RL 14.1 : Topics
What is a Process, Process Control Block?
What is Multitasking? What is Mutithreading ? Thread vs Process?
2 Object-Oriented Programming (CS F213)
What is Process ? Process is nothing but an instance of program in execution (Unit of work in modern time-sharing systems) Modern operating systems can concurrently execute multiple processes.
3 Object-Oriented Programming (CS F213)
What is Process Control Block? https://en.wikipedia.org/wiki/Process_control_block
Process Control Block (PCB) is a Data Structure
Maintained by Operating System for each Process PCB Contains Information which is Required to Manage Each Process A Typical PCB Generally Contains 1. Program Counter (PC) 2. Stack Pointer (SP) 3. CPU Registers 4. Process State Information
4 Object-Oriented Programming (CS F213)
What is Context Switching?
Each Process Runs in its Own Address Space and OS
Maintains a Separate PCB for Each Process [No Sharing of Memory] Context Switching Means Shifting the Control of CPU from the Currently Running Process to Some Other Process During Context Switching the Present State of the Currently Executing Process is Saved onto a Specialized Memory Area Known as Stack. Program Counter, Stack Pointer and Other Important CPU Registers are loaded with values according to the Process which is Going to be Executed Next Context Switching is Quite Expensive in Processes
5 Object-Oriented Programming (CS F213)
What is Multitasking? The ability to have more than one program working at what seems like at the same time Examples : You can Edit while Printing a document Web Page may be Loading Multiple Images while Accepting User Inputs
6 Object-Oriented Programming (CS F213)
Multitasking Ways
Preemptive Multitasking OS Simply
Suspends the Currently Running Process and Shifts the Control to Some Other Process (Windows 3.1, Mac OS) Cooperative Multitasking OS Shifts the Control to Some Other Process Only When the Currently Running Process Yields control. (Non-preemptive Multitasking) Linux, Windows NT,95
7 Object-Oriented Programming (CS F213)
What is a Multithreading? Basis of Multi-Tasking at an Individual Program Level An Individual Program will Appear to do Multiple Tasks at the Same Time. Each Individual Task is Handled by a Thread A thread of execution is a program unit that is executed independently of other parts of the program [Light Weight Process] If a Program Creates Multiple Threads then all These Threads will Execute in the Same Address Space and Will Use the Same Data Structures [Sharing of Memory]
8 Object-Oriented Programming (CS F213)
Process vs Thread
S.No Process Thread
1 No Sharing of Memory Sharing of Memory
2 Can Not Corrupt Data Can Corrupt Data
Structures Structures 3 Context Switching is Context Switching is Expensive Cheaper