Introduction to Thread - Introduction To Threads 1 Topics...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Introduction To Threads
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Topics Basic Concepts Distinction between threads and processes Potential Parallelism Specifying Potential Parallelism in a Concurrent Programming Environment
Background image of page 2
3 Basic concepts What is a Program? A very large collection of instructions that are performed from beginning to end Our notion of a program include certain eccentricities Loops and jumps: flow control within the instruction execution stream If the programming instructions were squares on a game board, we would observe the following Places where we stall: wait for input Squares that we cross many times: loops Spots we don’t cross at all: branch/jump We have one way into our program and one way out of it
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Computer Architecture Multitasking operating system The operating system interleave the execution of many tasks giving the illusion that all the tasks are being executed simultaneously on their own dedicated CPU Task are executed within the context of a construct called a process Process A schedulable entity and hold all the resources needed for the execution of the task Scheduling Policy: LRU, Round Robin Context Switch Assigning the CPU from one process to another Preemptive: higher priority process takes precidence Quantum completion: time slice exhausted Relinquish due to wait on I/O completion
Background image of page 4
5 Effect of Multitasking Program can be broken into a number sub tasks If we can get the computer to executed some of the tasks at the same time, with no change in our program’s results Overall task get as much processing as it needs Overall task will complete in a shorter period of time System with single processor execution of the sub tasks will be interleaved Multi-Processor system Sub tasks will be executed in parallel on multiple CPUs
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Landscape Before Threads Processes were the only way to deliver the sub tasks to the processor or processors Parent processes forked child processes to perform sub tasks In this model, each sub task exist in its own process Threads gives us an alternative to the process model Why do we even need an alternative Difficulty/complexity of working with process model Process model is not very efficient
Background image of page 6
7 The Thread Model This model takes a process and divides it into two parts The process : contains resources used across the whole program (process wide information) such as global instructions global data Thread : contains information related to the execution state, such as program counter: pointer to the current instruction being executed Stack: store automatic variables for procedures and procedure return information
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 A Simple C Program Void do_one_thing(int *); Void do_another_thing(int *); Void do_wrap_up(int, int); Int r1=0, r2=0; Main() { do_one_thing(&r1); do_another_thing(&r2); do_wrap_up(r1, r2); } Void do_one_thing(int *pnum_times) { int i, j, x;
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 33

Introduction to Thread - Introduction To Threads 1 Topics...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online