Presentation is loading. Please wait.

Presentation is loading. Please wait.

PROCESSES & THREADS ADINA-CLAUDIA STOICA.

Similar presentations


Presentation on theme: "PROCESSES & THREADS ADINA-CLAUDIA STOICA."— Presentation transcript:

1 PROCESSES & THREADS ADINA-CLAUDIA STOICA

2 CONTENTS 1.Process 2.Thread 3.Processes VS. Threads
4.Why choose Process over Thread, or Thread over Process?

3 1.WHAT IS A PROCESS? A process is an instance of program execution. This means, for example, that if you open up two browser windows then you have two processes, even though they are running the same program.

4 Some essential resources every process needs are registers, a program counter, and a stack.
The “registers” are data holding places that are part of the computer processor (CPU). A register may hold an instruction, a storage address, or other kind of data needed by the process.

5 The “program counter,” also called the “instruction pointer,” keeps track of where a computer is in its program sequence. The “stack” is a data structure that stores information about the active subroutines of a computer program and is used as scratch space for the process. It is distinguished from dynamically allocated memory for the process that is known as the “heap.”

6 A COMPUTER PROCESS

7 There can be multiple instances of a single program, and each instance of that running program is a process. Each process has a separate memory address space, which means that a process runs independently and is isolated from other processes. It cannot directly access shared data in other processes. Switching from one process to another requires some time (relatively) for saving and loading registers, memory maps, and other resources.

8 This independence of processes is valuable because the operating system tries its best to isolate processes so that a problem with one process doesn’t corrupt or cause havoc with another process. You’ve undoubtedly run into the situation in which one application on your computer freezes or has a problem and you’ve been able to quit that program without affecting others.

9 The life-cycle of a process can be described by a state diagram which has states representing the execution status of the process at various times and transitions that represent changes in execution status.

10 The life-cycle of a process

11 Ready state A process in the ready state has all of the resources that it needs for further execution except for a processor. It is normally held in a ready queue until a processor becomes available.

12 Running state A process in the running state has all of the resources that it needs for further execution, including a processor.

13 Blocked state A process that needs some resource other than a processor for further execution is in a blocked state. It is usually placed in a queue waiting for the needed resource.

14 Threads A thread is the unit of execution within a process. A process can have anywhere from just one thread to many threads.

15 Process vs thread

16 When a process starts, it is assigned memory and resources
When a process starts, it is assigned memory and resources. Each thread in the process shares that memory and resources. In single-threaded processes, the process contains one thread. The process and the thread are one and the same, and there is only one thing happening.

17 In multithreaded processes, the process contains more than one thread, and the process is accomplishing a number of things at the same time

18 We talked about the two types of memory available to a process or a thread, the stack and the heap. It is important to distinguish between these two types of process memory because each thread will have its own stack, but all the threads in a process will share the heap.

19 Threads are sometimes called lightweight processes because they have their own stack but can access shared data. Because threads share the same address space as the process and other threads within the process, the operational cost of communication between the threads is low, which is an advantage. The disadvantage is that a problem with one thread in a process will certainly affect other threads and the viability of the process itself.

20 Threads vs processes 1.The program becomes one or more running processes. 2.Processes are typically independent of each other, 3.While threads exits as the subset of a process 4.Threads can communicate with each other more easily than processes can, 5.But threads are more vulnerable to problems caused by other threads in the same process

21 Process Processes are heavyweight operations
Each process has its own memory space Inter-process communication is slow as processes have different memory addresses Context switching between processes is more expensive Processes don’t share memory with other processes

22 Thread Threads are lighter weight operations
Threads use the memory of the process they belong to Inter-thread communication can be faster than inter- process communication because threads of the same process share memory with the process they belong to Context switching between threads of the same process is less expensive Threads share memory with other threads of the same process

23 Why Choose Process over Thread, or Thread over Process?
So, how would a programmer choose between a process and a thread when creating a program in which she wants to execute multiple tasks at the same time? Let’s look at a real world example with a program that many of us use, Google Chrome.

24 When Google was designing the Chrome browser, they needed to decide how to handle the many different tasks that needed computer, communications, and network resources at the same time. Each browser window or tab communicates with multiple servers on the internet to retrieve text, programs, graphics, audio, video, and other resources, and renders that data for display and interaction with the user. In addition, the browser can open many windows, each with many tasks.

25 Google had to decide how to handle that separation of tasks
Google had to decide how to handle that separation of tasks. They chose to run each browser window in Chrome as a separate process rather than a thread or many threads, as is common with other browsers. Doing that brought Google a number of benefits. Running each window as a process protects the overall application from bugs and glitches in the rendering engine and restricts access from each rendering engine process to others and to the rest of the system. Isolating a JavaScript program in a process prevents it from running away with too much CPU time and memory and making the entire browser non-responsive.

26 Google made a calculated trade-off with the multi- processing design
Google made a calculated trade-off with the multi- processing design. Starting a new process for each browser window has a higher fixed cost in memory and resources than using threads. They were betting that their approach would end up with less memory bloat overall.

27 Using processes instead of threads also provides better memory usage when memory gets low. An inactive window is treated as a lower priority by the operating system and becomes eligible to be swapped to disk when memory is needed for other processes. That helps keep the user-visible windows more responsive. If the windows were threaded, it would be more difficult to separate the used and unused memory as cleanly, wasting both memory and performance.

28 Bibliography 1. programs-processes-and-threads/ 2. and-threads.xhtml 3. us/windows/desktop/procthread/processes-and- threads


Download ppt "PROCESSES & THREADS ADINA-CLAUDIA STOICA."

Similar presentations


Ads by Google