3 Pages

threads

Course: CS 414, Fall 2008
School: UVA
Rating:
 
 
 
 
 

Word Count: 846

Document Preview

of 2/8/2008 Components a Process Program vs. process Process: object code of program (program text in UNIX) data on which the program will execute (from file or user interaction) resources required by the program (e.g., files) status of the process execution (e.g., PC and registers) Process Creation Parent process creates children processes, which, in turn create other processes, forming a tree of processes...

Register Now

Unformatted Document Excerpt

Coursehero >> Virginia >> UVA >> CS 414

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
of 2/8/2008 Components a Process Program vs. process Process: object code of program (program text in UNIX) data on which the program will execute (from file or user interaction) resources required by the program (e.g., files) status of the process execution (e.g., PC and registers) Process Creation Parent process creates children processes, which, in turn create other processes, forming a tree of processes Resource sharing options Parent and child share all resources Children share subset of parent's resource Parent and child share no resources OS keeps process descriptor for each (generally) nonterminated process Traditional process: one address space and one flow of control Modern process: one address space and one or more flows of execution (threads) MORE LATER CS414: Operating Systems Execution options Parent and child execute concurrently Parent waits until children terminate Address Space Child duplicate of parent Child has a program loaded into it CS414: Operating Systems UNIX fork fork() creates new child process; one process executes fork() and two become ready Child is identical to parent except for return code from fork() Context Switch To run a process, the OS loads the values of the hardware registers (PC, SP, other registers) from the values stored in that process' PCB As the program executes, the CPU registers changes values (PC, SP) When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process Context-switching is overhead; the system does no useful work while switching The duration of a context switch is dependent on hardware Typically, time sharing OS performs 100 to 1000 context switches per second Picture on next slide. No part of the address space is shared parent and child communicate via pipes, explicitly shared memory, and shared files Parent can wait or continue Child can exec Example: your shell program; typing date forks a new process and then execs date; & after the command means it runs in parallel with your shell, otherwise it waits {DEMO} CS414: Operating Systems CS414: Operating Systems Context Switch Threads Original Process: address space and (single) flow of execution Thread we must separate address space (process or task) and flow of execution (thread or lightweight process, LWP) Motivation: Context switch between cooperating processes is HUGE (reestablishing address space); context switch between cooperating threads is cheap fork() of cooperating process is expensive; spawn of thread is cheap programming is easier(?) traditional UNIX CS414: Operating Systems CS414: Operating Systems embedded systems Windows, Solaris (POSIX) 1 2/8/2008 Threads and Address Space files, I/O PC Registers TCB1 PC Registers PC Registers TCB3 stacks TCB2 Sample Pthreads Code (1/2) // Pthreads example code // compile with: gcc -Wall pthreads_example.c -o pthreads_example // -lpthread execute with: ./pthreads_example (or "time ./pthreads_example") #include <pthread.h> #include <stdio.h> void thread_func (int num) { long long i,j; printf("Thread %d executing.\n", num); j = 0; for (i=0; i < 700000000U; ++i){ ++j; } printf("Thread %d done (%lld).\n", num, j); } gigabyte virtual address space CS414: Operating Systems CS414: Operating Systems Sample Pthreads Code (2/2) int main () { pthread_t thread1, thread2; pthread_t thread3, thread4; pthread_create(&thread1, NULL, (void *) &thread_func, (void *) 1); pthread_create(&thread2, NULL, (void *) &thread_func, (void *) 2); pthread_create(&thread3, NULL, (void *) &thread_func, (void *) 3); pthread_create(&thread4, NULL, (void *) &thread_func, (void *) 4); pthread_join(thread1, NULL); pthread_join(thread2, NULL); pthread_join(thread3, NULL); pthread_join(thread4, NULL); return 0; } CS414: Operating Systems CS414: Operating Systems DEMO Run the previous program on Linux Hmmm.. Why is top saying that only one of the CPUs is pegged at 100%? Why arent both pegged? Kernel Threads An improvement over only processes Creation/Switching still requires trapping to the kernel (system call) Thread data structure resides within the kernel: Thread Control Block (TCB) (execution state and scheduling info), so more complexity for the kernel In what sense? User-level Threads Faster than kernel-level threads Managed by run-time system in user-space (no kernel calls) Creation, switching, and synchronizing between thread calls can be done without kernel involvement Process-specific scheduling policies are possible Problem: whole process blocks when one thread blocks (there a...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

UVA - CS - 414
CS414: Operating Systems NachosAssignment 3: Synchronization Part Deux: Revenge of the Semaphores Due: 12:01 am on April 27th, 2008The purpose of this assignment is to further understand how to use semaphores to achieve synchronization. The basic
UVA - PHYS - 606
How Things Work II: DemonstrationsLecture1. Intro. &amp; SkatingTimeDemo NameDemo NumberDescriptionRide on a Razor Scooter, demonstrating the following about skating: When you're at rest on a level surface: - If not pushed, you stay stationar
UVA - PHYS - 605
Water, Steam, and Ice 1Water, Steam, and Ice 2Question: Water, Steam, and Ice A glass of ice water contains both ice and water. After a few minutes of settling, how do the temperatures of the ice and the water compare? The ice is colder than th
UVA - PHYS - 605
Woodstoves 1Woodstoves 2Question Woodstoves Which is more effective at heating a room: a black woodstove a white woodstoveWoodstoves 3Woodstoves 4Observations About Wood Stoves They burn wood inside closed fireboxes They often have
UVA - PHYS - 605
Ramps 1Ramps 2Question: RampsCan a ball ever push downward on a table with a force greater than the ball's weight?Ramps 3Ramps 4Observations About Ramps Lifting an object straight up is often difficult Pushing the object up a ramp is
UVA - PHYS - 605
Clocks 1Clocks 2Question: Clocks You're bouncing gently up and down at the end of a springboard, without leaving the board's surface. If you bounce harder, the time it takes for each bounce will become shorter become longer remain the sameC
UVA - PHYS - 605
Balls and Frisbees 1Balls and Frisbees 2Question: Balls and Frisbees A smooth, gentle river is flowing past a cylindrical post. At the sides of the post, is the water level higher, lower, or equal to its level in the open river?Balls and Frisb
UVA - PHYS - 605
Bumper Cars 1Bumper Cars 2Question: Bumper Cars You are riding on the edge of a spinning playground merry-go-round. If you pull yourself to the center of the merry-goround, what will happen to its rotation? It will spin faster. It will spin sl
UVA - PHYS - 605
Bouncing Balls 1Bouncing Balls 2Question: Bouncing Balls If you place a tennis ball on a basketball and drop this stack on the ground, how high will the tennis ball bounce? To approximately its original height. Much higher than its original he
UVA - PHYS - 605
Bicycles 1Bicycles 2Question: Bicycles How would raising the height of a small pickup truck affect its turning stability?1. Make it less likely to tip over. 2. Make it more likely to tip over. 3. Have no overall effect on its stability.Bicyc
UVA - PHYS - 605
Air Conditioners 1Air Conditioners 2Question Air ConditionersIf you operate a window air conditioner on a table in the middle of a room, the average temperature in the room will 1. become colder 2. become hotter 3. stay the sameAir Conditioner
UVA - PHYS - 605
Garden Watering 1Garden Watering 2Question: Garden Watering Water pours weakly from an open hose but sprays hard when you cover most of the end with your thumb. When is more water coming out of the hose? When the hose end is uncovered When you
UVA - PHYS - 605
Incandescent Light Bulbs 1Incandescent Light Bulbs 2Question: Incandescent Light Bulbs An incandescent light bulb contains some gas with the filament. How would removing the gas affect the bulbs energy efficiency? Make it more efficient Make i
UVA - PHYS - 605
Balloons 1Balloons 2Question: Balloons A helium balloon has mass, yet it doesnt fall to the floor. Is there a real force pushing up on the helium balloon?Balloons 3Balloons 4Observations About Balloons Balloons are held taut by the gas
UVA - PHYS - 605
Airplanes 1Airplanes 2Question: Airplanes As you ride in a jet airplane, the clouds are passing you at 600 mph. The air just in front of one of the huge jet engine intake ducts is traveling much faster than 600 mph. much slower than 600 mph.
UVA - PHYS - 605
Rockets 1Rockets 2Question: Rockets If there were no launch pad beneath the space shuttle at lift-off, the upward thrust of its engines would be approximately unchanged. approximately half as much. approximately zero.Rockets 3Rockets 4O
UVA - PHYS - 605
Carousels and Roller Coasters 1Carousels and Roller Coasters 2Question: Carousels and Roller Coasters When the wine glass was directly above my head, was there a force pushing up on the wine glass that kept the glass against the tray?Carousels
UVA - PHYS - 605
Falling Balls 1Falling Balls 2Question: Falling BallsSuppose that I throw a ball upward into the air. After the ball leaves my hand, is there any force pushing the ball upward?Falling Balls 3Falling Balls 4Observations About Falling Balls
UVA - PHYS - 605
Seesaws 1Seesaws 2Question: Seesaws You and a child half your height lean out over the edge of a pool at the same angle. If you both let go simultaneously, who will tip over faster and hit the water first?Seesaws 3Seesaws 4Observations Abo
UVA - PHYS - 605
Water Distribution 1Water Distribution 2Question: Water Distribution Water enters your home plumbing at ground level. Where will you get the strongest spray from a shower? In the ground floor shower In the basement shower In the second floor
UVA - PHYS - 605
Wheels 1Wheels 2Question: Wheels You are in a tremendous hurry and you want your car to accelerate as quickly as possible when the light turns green. Tire damage is not an issue. Will you accelerate faster if you &quot;burn rubber&quot; (skid your wheels)
UVA - PHYS - 631
Lecture 5 Friday July 13 Chapter 8Continuation of Conservation of Energy Two Sample Problems Spread sheet problem for you Hand out last years exam Misconception problems quitExternal Work (No Friction)BallW (eg. I could lift the ball) Ball-Ear
UVA - PHYS - 606
Physics Chat Room March 19 2008You are free to type text in the text line anytime. If you want to speak, click on the hand and I will give you the floor. Do this now just to say hello Agenda None of the questions in the chat room are graded. Start
UVA - PHYS - 606
Welcome to the Phys 606 Chat Room 8-9 PM Feb 20You are free to type text in the text line anytime. If you want to speak, click on the hand and I will give you the floor. Do this now just to say hello Then I will review some topics Focus on elementar
UVA - PHYS - 606
University of Virginia Department of PhysicsPhysics 606: How Things Work IILecture #20 Slides: Audio AmplifiersRecording Tape Sound current sent through ring-shaped electromagnet Split in ring develops north and south poles Nearby tape regio
UVA - PHYS - 606
University of Virginia Department of PhysicsPhysics 606: How Things Work IILecture #30 Slides: Fluorescent Lights IIAtomic Structure Electrons travel as waves Electron in an orbital doesn't emit light Electron emits light when changing orbit
UVA - PHYS - 606
University of Virginia Department of PhysicsPhysics 606: How Things Work IILecture #38 Slides: Nuclear Weapons IIStructure of Nucleus Nucleus contains two kinds of nucleons Protons are positively charged Neutrons are neutralNuclear Stabili
UVA - PHYS - 606
University of Virginia Department of PhysicsPhysics 606: How Things Work IILecture #22 Slides: ComputersQuestion: ComputersToday, the fastest PCs run at roughly 1.5 GHz. Someday, computers may run at 1,000,000 GHz. Compared to present computer
UVA - PHYS - 606
Question Previewerhttp:/www.webassign.net/v4cgiral5q@virginia/questions/previe.Case 2-3 - Bumper Cars (354474)Test / Preview Code Show New Randomization Open in Editor Print Show: All, None Key Solution Help/Hints MarkBumper cars are a popular
UVA - PHYS - 606
University of Virginia Department of PhysicsPhysics 606: How Things Work IILecture #36 Slides: Windows and Glass II and PlasticsTempered Glass Tempering glass Heat glass to softening point Cool outside of glass quickly Outside stiffens whil
UVA - PHYS - 606
University of Virginia Department of PhysicsPhysics 606: How Things Work IILecture #7 Slides: WheelsQuestion: WheelsYou are in a tremendous hurry and you want your car to accelerate as quickly as possible when the light turns green. Tire damag
UVA - PHYS - 606
University of Virginia Department of PhysicsPhysics 606: How Things Work IILecture #16 Slides: Power DistributionPower Power is energy per unit of time Power is measured in joules/second or watts Batteries are power sources Loads are power
UVA - PHYS - 606
University of Virginia Department of PhysicsPhysics 606: How Things Work IILecture #24 Slides: Radios IITank Circuit Inductor &amp; Capacitor share energy Charge flows back and forth through inductor Energy shifts back and forth between the two
UVA - PHYS - 606
University of Virginia Department of PhysicsPhysics 606: How Things Work IILecture #4 Slides: Force and WorkPhysics Concept Net Force The sum of all forces on an object. Determines object's acceleration.Newton's Third LawFor every force t
UVA - PHYS - 606
University of Virginia Department of PhysicsPhysics 606: How Things Work IILecture #14 Slides: Magnetically Levitated Trains II and FlashlightsElectromagnetic Induction Changing magnetic field electric field Electric field in conductor cu
UVA - PHYS - 606
University of Virginia Department of PhysicsPhysics 606: How Things Work IILecture #12 Slides: Xerographic Copiers IIMetals The Fermi level has empty levels just above it Like patrons in a partly fill theatre, electrons can move in response t
UVA - PHYS - 606
University of Virginia Department of PhysicsPhysics 606: How Things Work IILecture #34 Slides: Knives and SteelQuestion: Knives and SteelIf you take a steel paper clip and bend it repeatedly, will it become stiffer or less stiff with each new
UVA - PHYS - 606
University of Virginia Department of PhysicsPhysics 606: How Things Work IILecture #1 Slides: Introduction to course and SkatingQuestion: SkatingA rotary lawn mower spins its sharp blade rapidly over the lawn and cuts the tops of the grasses o
UVA - PHYS - 606
University of Virginia Department of PhysicsPhysics 606: How Things Work IILecture #26 Slides: MicrowavesQuestion:If you put a CD in a microwave oven, it willMicrowave Ovens1. do nothing. 2. burn up the microwave oven. 3. burn up the CD.O
UVA - PHYS - 606
Welcome to the Phys 606 Chat Room 8-9 PM Apr 16 You are free to type text in the text line anytime. If you want to speak, Click on the hand and I will give you the floor. We all should do this just to say hello Then I will review selected topics.
UVA - PHYS - 606
University of Virginia Department of PhysicsPhysics 606: How Things Work IILecture #5 Slides: SeesawsWork Lifting Ball Going straight up: Force is large Distance is smallForces on a RampSupport Net Forcedistancework =force Weight
UVA - CS - 101
UVA - CS - 101
Applications of Scientific Computing9. Scientific ComputingScience and engineering challenges.! !Commercial applications.! !!!!!!!!!!Fluid dynamics. Seismic surveys. Plasma dynamics. Ocean circulation. Electronics design.
UVA - CS - 101
Overview4.1 - 4.2 Analysis of AlgorithmsAnalysis of algorithms. Framework for comparing algorithms and predicting performance. Scientific method. Observe some feature of the universe. Hypothesize a model that is consistent with observation. Predi
UVA - CS - 686
Dependable ComputingDependable Computing CS686John C. Knight Department of Computer Science University of Virginia knight@cs.virginia.edu 434.982.2216 John C. Knight, 2009 - All rights reserved.Beginning of Course MemoReadit is on the Web site
UVA - SBB - 801
!&quot; &quot; ) ( )# !$% &amp; % &quot; ( &quot; , % . ( %'&quot; * +&quot;&quot;,&quot; / (,)( -/ &quot; ) 1 ( 2 * % &quot; ( ( %&quot; &quot; &quot; ( 3 ) ( ( ( (&quot; *( ( 0 % + 4 &quot; ( &quot;*) #5 6$ &quot; &quot; ( % 4( % )/0 ) ( ( ( ( # ! 9 &amp;: &quot; &quot; * ) &quot; / &quot; &quot; / 7 &quot; / 7 ) 89% &quot; &quot;) ' ) (* &quot; $% %
UVA - AE - 554
Components of Galaxies Gas The Importance of Gas Fuel for star formation (H2) Tracer of galaxy kinematics/mass (HI) Tracer of dynamical history of interaction between galaxies (HI)Much of this material has been / will be covered in your ISM
UVA - AST - 554
Components of Galaxies Gas The Importance of Gas Fuel for star formation (H2) Tracer of galaxy kinematics/mass (HI) Tracer of dynamical history of interaction between galaxies (HI)Much of this material has been / will be covered in your ISM
UVA - AE - 554
AST 554 - Homework #1Due February 24, 2009 Note: This homework covers some of the topics in the preliminary lectures up through &quot;Components of Galaxies: Gas&quot;. The problems are intended to be relatively straight-forward. Please remember to define al
UVA - AST - 554
AST 554 - Homework #1Due February 24, 2009 Note: This homework covers some of the topics in the preliminary lectures up through &quot;Components of Galaxies: Gas&quot;. The problems are intended to be relatively straight-forward. Please remember to define al
UVA - AE - 554
Components of Galaxies: Dark MatterDark Matter: Any Form of matter whose existence is inferred solely through its gravitational effects. -B&amp;T, pg 590 Nature of Major Component of Universe Galaxy Formation Fate of the UniverseEvidence for Dark M
UVA - AST - 554
Components of Galaxies: Dark MatterDark Matter: Any Form of matter whose existence is inferred solely through its gravitational effects. -B&amp;T, pg 590 Nature of Major Component of Universe Galaxy Formation Fate of the UniverseEvidence for Dark M
UVA - AE - 554
The Astrophysical Journal, 686:948965, 2008 October 20# 2008. The American Astronomical Society. All rights reserved. Printed in U.S.A.ATHE RESOLVED PROPERTIES OF EXTRAGALACTIC GIANT MOLECULAR CLOUDSAlberto D. Bolatto,1 Adam K. Leroy,2 Erik Ros
UVA - AST - 554
The Astrophysical Journal, 686:948965, 2008 October 20# 2008. The American Astronomical Society. All rights reserved. Printed in U.S.A.ATHE RESOLVED PROPERTIES OF EXTRAGALACTIC GIANT MOLECULAR CLOUDSAlberto D. Bolatto,1 Adam K. Leroy,2 Erik Ros
UVA - AE - 554
The Astrophysical Journal, 629:6171, 2005 August 10# 2005. The American Astronomical Society. All rights reserved. Printed in U.S.A.THE RELATIONSHIP BETWEEN LUMINOSITY AND BROAD-LINE REGION SIZE IN ACTIVE GALACTIC NUCLEIShai Kaspi,1, 2 Dan Maoz,1
UVA - AST - 554
The Astrophysical Journal, 629:6171, 2005 August 10# 2005. The American Astronomical Society. All rights reserved. Printed in U.S.A.THE RELATIONSHIP BETWEEN LUMINOSITY AND BROAD-LINE REGION SIZE IN ACTIVE GALACTIC NUCLEIShai Kaspi,1, 2 Dan Maoz,1
UVA - AE - 554
THE ASTROPHYSICAL JOURNAL, 507 : 615654, 1998 November 10( 1998. The American Astronomical Society. All rights reserved. Printed in U.S.A.ROTATING NUCLEAR RINGS AND EXTREME STARBURSTS IN ULTRALUMINOUS GALAXIES D. DOWNESInstitut de Radio Astronomi
UVA - AST - 554
THE ASTROPHYSICAL JOURNAL, 507 : 615654, 1998 November 10( 1998. The American Astronomical Society. All rights reserved. Printed in U.S.A.ROTATING NUCLEAR RINGS AND EXTREME STARBURSTS IN ULTRALUMINOUS GALAXIES D. DOWNESInstitut de Radio Astronomi
UVA - AE - 554
The Astronomical Journal, 124:788810, 2002 August# 2002. The American Astronomical Society. All rights reserved. Printed in U.S.A.MOLECULAR GAS IN ELLIPTICAL GALAXIES: DISTRIBUTION AND KINEMATICS L. M. YoungPhysics Department, New Mexico Institut
UVA - AST - 554
The Astronomical Journal, 124:788810, 2002 August# 2002. The American Astronomical Society. All rights reserved. Printed in U.S.A.MOLECULAR GAS IN ELLIPTICAL GALAXIES: DISTRIBUTION AND KINEMATICS L. M. YoungPhysics Department, New Mexico Institut
UVA - AST - 554
1997MNRAS.289.766H1997MNRAS.289.766H1997MNRAS.289.766H1997MNRAS.289.766H1997MNRAS.289.766H1997MNRAS.289.766H1997MNRAS.289.766H1997MNRAS.289.766H1997MNRAS.289.766H1997MNRAS.289.766H1997MNRAS.289.766H1997MNRAS.289.766H1997MNRAS.