Docsity

CS 449: Threads and Multiprogramming - Prof. Jonathan R. Misurda, Study notes of Computer Science

Toggle sidebar
bg1
CS 449 - Threads
JonathanMisurda
Multiprogramming
A
C
D
Single$PC
(CPU’spointofview)
B
B
A
B
C
D
Time
ABCD
Multiple$PCs
(processpointofview)
Onestreamofinstructions
Isolatedaddressspacesthat
arenotinterrupted
Life Cycle of a Process
Blocked
(waiting)
Created
Exit
Ready
Running
Thread
Astreamofinstructionsandtheir
associatedstate
Processes and Threads
Kernel Kernel
ThreadsThreads
System
space
User
space
Process1Process2Process3Process1
Thread State
Perprocessitems
Addressspace
Openfiles
Childprocesses
Signals&handlers
Accountinginfo
Globalvariables
Perprocessitems
Addressspace
Openfiles
Childprocesses
Signals&handlers
Accountinginfo
Globalvariables
Perthreaditems
Programcounter
Registers
Stack&stackpointer
State
Perthreaditems
Programcounter
Registers
Stack&stackpointer
State
Perthreaditems
Programcounter
Registers
Stack&stackpointer
State
Perthreaditems
Programcounter
Registers
Stack&stackpointer
State
Perthreaditems
Programcounter
Registers
Stack&stackpointer
State
Perthreaditems
Programcounter
Registers
Stack&stackpointer
State
pf2

Partial preview of the text

Download CS 449: Threads and Multiprogramming - Prof. Jonathan R. Misurda and more Study notes Computer Science in PDF only on Docsity!

CS 449 - Threads

Jonathan Misurda

[email protected]

Multiprogramming

A

C

D

Single $PC

(CPU’s point of view)

B

B

A

B

C

D

Time

A B C D

Multiple $PCs

(process point of view)

One stream of instructions

Isolated address spaces that

are not interrupted

Life Cycle of a Process

Blocked

(waiting)

Created

Exit

Ready

Running

Thread

A stream of instructions and their

associated state

Processes and Threads

Kernel Kernel

Threads Threads

System

space

User

space

Process 1 Process 2 Process 3 Process 1

Thread State

Per process items

Address space

Open files

Child processes

Signals & handlers

Accounting info

Global variables

Per process items

Address space

Open files

Child processes

Signals & handlers

Accounting info

Global variables

Per thread items

Program counter

Registers

Stack & stack pointer

State

Per thread items

Program counter

Registers

Stack & stack pointer

State

Per thread items

Program counter

Registers

Stack & stack pointer

State

Per thread items

Program counter

Registers

Stack & stack pointer

State

Per thread items

Program counter

Registers

Stack & stack pointer

State

Per thread items

Program counter

Registers

Stack & stack pointer

State

Multithreading in Action

Kernel

When becomes dissolve connected in the (^) thenecessary them (^) politicalCourse with of for bands another, human one peoplewhich events, and have toto it assume earth, which Nature's thetheamong God separate Laws entitle the of (^) Naturepowers and them, equal and ofa the station (^) decentof to respect requires causes (^) whichto that the (^) they impelopinions should them of mankinddeclareto the the separation. We that they certain hold all are men (^) unalienabletheseendowed are truths created by Rights, to their be equal, self Creator that‐ that evident,among with these of rights, among Happiness. are Governments Men, Life,‐‐ deriving LibertyThat to (^) are and securetheir theinstituted just pursuitthese powers from That Government the whenever consent becomes any of (^) Formthe governed, of ‐‐ destructive of and laying the to People (^) itsinstitute foundation of these to (^) newalter ends, Government, on or (^) suchto it abolish is theprinciples Right it, and as effect Prudence, to organizing them their shall (^) indeed,Safety its seempowers and will most Happiness.dictate in suchlikely that form, to Governments not causes; be changed and accordingly long for established light (^) alland transient should

Multithreaded Webserver

Kernel

Network

connection

Worker

thread

Webcache page

while(TRUE) {

getNextRequest(&buf);

handoffWork(&buf);

while(TRUE) {

waitForWork(&buf);

lookForPageInCache(&buf,&page);

if(pageNotInCache(&page)) {

readPageFromDisk(&buf,&page);

returnPage(&page);

Webserver

process

User Threads vs. Kernel Threads

Kernel

Threading

library

Thread

state

Process

state

Kernel

Thread

Process

Thread

state

Processstate