Docsity

15-410 Class Notes: Threads, Synchronization, and Race Conditions, Slides of Operating Systems

Partial preview of the text

Download 15-410 Class Notes: Threads, Synchronization, and Race Conditions and more Slides Operating Systems in PDF only on Docsity!

15-410, F'

The Thread

Sep. 11, 2013

Dave Eckhardt

Dave Eckhardt

Todd Mowry

Todd Mowry

L07_Thread

“Real concurrency – in which one program actually

continues to function while you call up and use

another – is more amazing but of small use to the

average person. How many programs do you have

that take more than a few seconds to perform any

task?” – NYT, 4/25/

15-410, F'

Synchronization

Partner sign-up

Partner sign-up

Looks like we may be done!

Though somebody may drop during P

Project 1

Project 1

By end of Wednesday...

Console (output) should be “doing something”, “not far”

Should have “some progress” for kbd, timer

»

Should really have at least “solid design”

»

Better to have handled one interrupt once

Write good code

Write good code

Console driver will be used (and extended) in P

15-410, F'

Readings

Textbook chapters

Textbook chapters

OSC

Already: Chapters 1 through 3

Today: Chapter 4 (roughly)

Soon: Chapters 6 & 7

»

Transactions (6.9) will be deferred

OS:P+P

Already: Chapters 1 through 3

Today: Chapter 4 (roughly/partly)

Soon: Chapter 6

Remember: reading schedule is on the “schedule” page

15-410, F'

Book Report Goals

Some of you are going to grad. school

Some of you are going to grad. school

Some of you are wondering about grad. school

Some of you are wondering about grad. school

Some of you are

Some of you are in

in grad. school

grad. school

You should be able to read a Ph.D. dissertation

More generally

More generally

Looking at something in depth is different

Not like a textbook

15-410, F'

Book Report

Read the “handout”

Read the “handout”

Browse the already-approved list

Browse the already-approved list

Pick something (soon)

Pick something (soon)

“Don't make me stop the car...”

Read a bit before you sleep at night

Read a bit before you sleep at night

or: before you sleep in the morning

and/or: Thanksgiving break / Spring break

Assignment recommended by previous OS students!

Assignment recommended by previous OS students!

They recommend starting early, too

15-410, F'

Road Map

Thread lecture

Thread lecture

Synchronization lectures

Synchronization lectures

Probably three

Yield lecture

Yield lecture

This is important

This is important

When you leave here, you will use threads

Understanding threads will help you understand the

kernel

Please make sure you

Please make sure you understand

understand threads

threads

We'll try to help by assigning you P

15-410, F'

Single-threaded Process

Stack

Code

Data

Heap

Registers

stdin

stdout

timer

15-410, F'

Multi-threaded Process

stdin

stdout

timer

Code

Data

Heap

Stack

Registers

Stack

Registers

Stack

Registers

15-410, F'

Why threads?

Shared access to data structures

Shared access to data structures

Responsiveness

Responsiveness

Speedup on multiprocessors

Speedup on multiprocessors

15-410, F'

Shared access to data structures

Database server for multiple bank branches

Database server for multiple bank branches

Verify multiple rules are followed

Account balance

Daily withdrawal limit

Multi-account operations (transfer)

Many accesses, each modifies tiny fraction of database

Server for a multi-player game

Server for a multi-player game

Many players

Access (& update) shared world state

Scan multiple objects

Update one or two objects

15-410, F'

Shared access to data structures

Thread

Thread per player

per player

Game objects inside single memory address space

Each thread can access & update game objects

Shared access to OS objects (files)

Thread-switch is cheap

Thread-switch is cheap

Store N registers

Load N registers

15-410, F'

Responsiveness

Cancel” button vs. decompressing large JPEG

Cancel” button vs. decompressing large JPEG

Handle mouse click during 10-second process

Map (x,y) to “cancel button” area

Change color / animate shadow / squeak / ...

Verify that button-release happens in button area of screen

...without JPEG decompressor understanding clicks

Actually stopping the decompressor is a separate issue

Threads allow the user to register intent while it's running

15-410, F'

Kinds of threads

User-space (N:1)

User-space (N:1)

Kernel threads (1:1)

Kernel threads (1:1)

Many-to-many (M :N)

Many-to-many (M :N)

15-410, F'

User-space threads (N:1)

Internal threading

Internal threading

Thread library adds

threads to a process

Thread switch “just

swaps registers”

Small piece of asm code

Maybe called yield()

Code

Data

Heap

Stack

Stack

Registers

Stack