Lec4_thread

Lec4_thread - Announcement CSE120 Principles of Operating...

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

View Full Document Right Arrow Icon
1 CSE120 Principles of Operating Systems Prof Yuanyuan (YY) Zhou Lecture 4: Threads Apr 6th, 2011 4/5/2011 CSE 120 – Lecture 4 – Threads 2 Announcement Homework 1 released this week ( optional) Project 0 due today Review What is a process? States of a process? How many processes can run at any instant of time on uni-processor machine? What is a context switch? What is involved in a context switch? What is a process-control block (PCB)? Name one piece of information in a PCB 4/5/2011 CSE 120 – Lecture 4 – Threads 3 4/5/2011 CSE 120 – Lecture 4 – Threads 4 Processes Recall that a process includes many things An address space (defining all the code and data pages) OS resources (e.g., open files) and accounting information Execution state (PC, SP, regs, etc.) Creating a new process is costly because of all of the data structures that must be allocated and initialized Recall struct proc in Solaris …which does not even include page tables, perhaps TLB flushing, etc. Communicating between processes is costly because most communication goes through the OS Overhead of system calls and copying data
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 4/5/2011 CSE 120 – Lecture 4 – Threads 5 Parallel Programs To execute these programs we need to Create several processes that execute in parallel Have the OS schedule these processes in parallel (logically or physically) This situation is very inefficient Space : PCB, page tables, etc. Time : create data structures, fork and copy addr space, etc. Solution: possible to have cooperating “processes”? 4/5/2011 CSE 120 – Lecture 4 – Threads 6 Rethinking Processes What is similar in these cooperating “processes”? They all share the same code and data (address space) They all share the same privileges They all share the same resources (files, sockets, etc.) What don’t they share? Each has its own execution state: PC, SP, and registers Key idea : Why don’t we separate the concept of a process from its execution state? Process : address space, privileges, resources, etc. Execution state : PC, SP, registers Exec state also called thread of control , or thread 4/5/2011 CSE 120 – Lecture 4 – Threads 7 Threads Modern OSes (Mach, Chorus, NT, modern Unix) separate the concepts of processes and threads The thread defines a sequential execution stream within a process (PC, SP, registers) The process defines the address space and general process attributes (everything but threads of execution) A thread is bound to a single process A process, however, can have multiple threads Threads become the unit of scheduling Processes are now the containers in which threads execute 4/5/2011 CSE 120 – Lecture 4 – Threads 8 Threads: Lightweight Processes A sequential execution stream within a process (a) Three processes each with one thread (b) One process with three threads Environment (resource) execution
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 02/26/2012 for the course CSE 120 taught by Professor Staff during the Spring '08 term at UCSD.

Page1 / 9

Lec4_thread - Announcement CSE120 Principles of Operating...

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