lecture02

lecture02 - CS140 - Winter 2008 - Handout #2 Today's...

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

View Full Document Right Arrow Icon
CS140 - Winter 2008 - Handout #2 CS 140: OS hacking Lecture 2: threads & processes Mendel Rosenblum Winter ‘08 Today’s adventure ± What are processes, threads? ± What are they for? ± How do they work? ± Threads vs processes? ± Readings: 6 th ed: Silberschatz/Galvin: Ch 4 (skip 4.{5,6}), Ch 5. 7 th ed: Silberschatz/Galvin: Ch 3 (skip 3.{4-6}), Ch 4. ± Hundreds of things going on in system ± How to make simple? Separate each in isolated process. OS deals with one thing at a time, they just deal with OS *THE* universal trick for managing complexity: decomposition (“reductionism”) Why processes? Simplicity gcc emacs nfsd lpr ls www emacs nfsd lpr ls www OS OS ± I/O parallelism: Overlap execution: make 1 CPU into many (Real parallelism: > 1 CPU (multiprocessing)) ± Completion time: B’s completion time = 100s (A + B) So overlap Why processes? Speed emacs (Wait for input) (Wait for input) gcc A B A B 20 s 80 s Completion time for B? A? 10 s Processes in the real world ± Processes, parallelism fact of life much longer than OSes have been around Companies use parallelism for more throughput: 1 worker = 100 widgets? hire 100 to make 10,000. ± Can you always partition work to speed up job? Ideal: N-fold speedup Reality: bottlenecks + coordination overhead Example: CS140 group project (More abstractly: easy to increase throughput, reducing latency more difficult) What is a thread? ± In theory: Turing machine tape (state), tape head (position) ± In practice: What’s needed to run code on CPU “execution stream in an execution context” Execution stream: sequential seq. of instructions ± CPU execution context (1 thread) State: stack, heap, registers Position: program counter register ± OS execution context (n threads): identity + open file descriptors, page table, … add r1, r2, r3 sub r2, r3, r10 st r2, 0(r1)
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS140 - Winter 2008 - Handout #2 What is a process? ± Process: thread + address space or, abstraction representing what you need to run thread on OS (open files, etc) ± Address space: encapsulates protection address state passive, threads active ± Why separate thread, process? Many situations where you want multiple threads per address space (servers, OS, parallel program) AltaVista int c; int main() { printf(“hello”); } Process != Program ± Program: code + data passive ± Process: running program state: registers, stack, heap… position: Program counter ± We both run Firefox: same program, different process stack heap data code int a; main() How to make one?
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/24/2008 for the course CS 140 taught by Professor Rosenblum during the Winter '08 term at Stanford.

Page1 / 5

lecture02 - CS140 - Winter 2008 - Handout #2 Today's...

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

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