081029slides_handouts

081029slides_handouts - Priorities Landed on Mars, July 4,...

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

View Full Document Right Arrow Icon
1 UVa CS205 Engineering Software 2008 Priorities Landed on Mars, July 4, 1997 Sojourner Rover UVa CS205 Engineering Software 2008 Counter c = new Counter (); IncThread ithread = new IncThread (c); DecThread dthread = new DecThread (c); ithread.setPriority (Thread.NORM_PRIORITY); ithread.start (); dthread.setPriority (Thread.MAX_PRIORITY); dthread.start (); Running inc thread: Thread[Thread-0,5,main] / Value: 1 Running dec thread: Thread[Thread-1,10,main] / Value: 0 Running inc thread: Thread[Thread-0,5,main] / Value: 1 Running dec thread: Thread[Thread-1,10,main] / Value: 0 Running inc thread: Thread[Thread-0,5,main] / Value: 1 Running dec thread: Thread[Thread-1,10,main] / Value: 0 Running inc thread: Thread[Thread-0,5,main] / Value: 1 Running dec thread: Thread[Thread-1,10,main] / Value: 0 UVa CS205 Engineering Software 2008 Priorities ± In general, threads with higher priorities will be scheduled preferentially. ± There are no guarantees: up to Java scheduler Thread class: void setPriority (int newPriority) // MODIFIES: this // EFFECTS: Changes the priority of this // thread to newPriority. UVa CS205 Engineering Software 2008 Priorities, Priorities ithread.setPriority (Thread.NORM_PRIORITY); ithread.start (); dthread.setPriority (Thread.MIN_PRIORITY); dthread.start (); The ithread should run more than the dthread, but there is no guarantee. Thread.MIN_PRIORITY Thread.NORM_PRIORITY Thread.MAX_PRIORITY
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 UVa CS205 Engineering Software 2008 Question ± Is it possible for a thread to simultaneously be in the wait set for more than one object? “… supporting arbitrary heterogenous "event“ types (locks, conditions, barriers, latches, IO etc) is not feasible in Java… For general locking it is very rare to want to lock either A or B and not care which; more commonly you want A and B, and that can be done explicitly… Most of our blocking abstractions do support the notion of waiting for
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 04/05/2010 for the course CS 150 taught by Professor Humphreys,g during the Spring '08 term at UVA.

Page1 / 5

081029slides_handouts - Priorities Landed on Mars, July 4,...

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