DOC PREVIEW
Berkeley COMPSCI 162 - Lecture Notes

This preview shows page 1 out of 4 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 162 Operating Systems and Systems Programming Answer Decompose hard problem into simpler ones Instead of dealing with Professor Anthony Joseph Spring 2003 everything going on at once separate into logical abstractions that we can deal with one at a time Lecture 3 Concurrency Processes Threads and Address Spaces 3 0 Processes The notion of a process is a central concept for Operating Systems Main point What are processes Process Operating system abstraction to represent what is needed to run a single How are they related to threads and address spaces program this is the traditional UNIX definition 3 1 Concurrency 3 1 1 Definitions Formally a process is a sequential stream of execution in its own address space 3 2 1 Uniprogramming one process at a time e g MS DOS Macintosh Easier for operating system builder get rid of problem of concurrency by defining it away For personal computers idea was one user does only one thing at a time Harder for user can t work while waiting for printer Multiprogramming more than one process at a time UNIX OS 2 Windows NT Note This is often called multitasking but multitasking sometimes has other meanings see below so not used in this course 3 1 2 3 2 Two parts to a traditional Unix process 1 Sequential program execution the code in the process is executed as a single sequential stream of execution no concurrency inside a process This is known as a thread of control 2 State Information everything specific to a particular execution of a program Encapsulates protection address space CPU registers Main memory contents of address space I O state in UNIX this is represented by file descriptors The basic problem of concurrency Hardware single CPU I O interrupts API users think they have machine to themselves OS has to coordinate all the activity on a machine multiple users I O interrupts etc How can it keep all these things straight CS 162 Spring 2003 Lecture 3 1 7 CS 162 Spring 2003 Lecture 3 2 7 3 2 2 Process Program 3 3 A program is for example a set of C statements or commands vi ls main A main A PROGRAM Multiple Threads of Control The traditional notion of a Process can be extended to allow for additional concurrency Thread a sequential execution stream within a process concurrency Sometimes called a lightweight process Provides the illusion that each activity or thread is running on its own CPU entirely sequentially heap Address space all the state needed to run a program literally all the addresses that can be touched by the program Provides the illusion that a program is running on its own machine protection stack A main registers PC PROCESS 3 3 1 1 More to a process than just a program Program is just part of process state I run emacs on lecture txt you run emacs on homework java same program different processes Why separate the concept of a thread from that of a process 1 Discuss the thread part of a process concurrency separately from the address space part of a process protection 2 Many situations where you want multiple threads per address space Question Why would you want this 2 Less to a process than a program A program can invoke more than one process to get the job done cc starts up cpp cc1 cc2 as ld each are programs themselves Multithreading a single program made up of a number of different concurrent activities sometimes called multitasking as in Ada just to be confusing 3 3 2 Examples of multithreaded programs 1 Embedded systems elevators planes medical systems wristwatches etc Single program concurrent operations 2 Most modern OS kernels internally concurrent because have to deal with concurrent requests by multiple users But no protection needed within kernel 3 Database Server provides access to shared data by potentially many concurrent users Also has background utility processing that must get done CS 162 Spring 2003 Lecture 3 3 7 CS 162 Spring 2003 Lecture 3 4 7 A int tmp if tmp 2 B printf tmp B C C A 2 4 Network servers user applications that get multiple requests concurrently off the network Again single program multiple concurrent operations examples file servers Web server and airline reservation systems 5 Parallel programming split program into multiple threads to make it run faster This is called multiprocessing Multiprogramming multiple jobs or processes Multiprocessing multiple CPUs A 1 Some multiprocessors are in fact uniprogrammed multiple threads in one address space but only run one program at a time 3 3 3 A tmp 2 C B A tmp 1 Execution stack Threads encapsulate concurrency address spaces encapsulate protection Keeps a buggy program from trashing everything else on the system Thread State Address state is passive thread is active What state does a thread have Some state shared by all threads in a process address space Contents of memory global variables heap I O state file system Some state private to each thread each thread has its own copy CPU registers including program counter Execution stack what is this 3 4 Classification Real operating systems have either One or many address spaces One or many threads per address space Execution stack where parameters temporary variables and return PC are kept while called procedures are executing for example where are A s variables kept while B C are executing of address spaces one many of threads per address space One MS DOS Macintosh traditional UNIX embedded systems JavaOS Pilot PC Mach OS 2 Windows 95 Windows NT Solaris Linux HP UX Many Examples 1 MS DOS one thread one address space 2 Traditional UNIX one thread per address space many address spaces CS 162 Spring 2003 Lecture 3 5 7 CS 162 Spring 2003 Lecture 3 6 7 3 Mach Microsoft NT new UNIX Linux Solaris HPUX many threads per address space many address spaces 4 Embedded systems Geoworks VxWorks JavaOS etc Also Pilot the operating system on the first personal computer ever built many threads one address space idea was no need for protection if single user 3 5 Summary Processes have two parts threads and address spaces Book talks about processes when this concerns concurrency really talking about thread portion of a process when this concerns protection really talking about address space portion of a process CS 162 Spring 2003 Lecture 3 7 7


View Full Document

Berkeley COMPSCI 162 - Lecture Notes

Documents in this Course
Lecture 1

Lecture 1

12 pages

Nachos

Nachos

41 pages

Security

Security

39 pages

Load more
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?