160 likes | 170 Views
cs205: engineering software university of virginia fall 2006. Concurrency on Mars. Kramer Sharp. JavaSpaces. Tuple Space Operations. write ( t ) – add tuple t to tuple space take ( s ) t – returns and removes tuple t matching template s
E N D
cs205: engineering software university of virginia fall 2006 Concurrency on Mars Kramer Sharp
Tuple Space Operations • write (t) – add tuple t to tuple space • take (s) t –returns and removes tuple t matching template s • read (s) t – same as take, except doesn’t remove t. Operations are atomic (even if space is distributed)
Distributed Ebay • Offer Item (String item, int minbid, int time): write (item, minbid, “owner”); sleep (time); take (item, formal bid, formal bidder); if (bidder “owner”) SOLD! • Bid (String bidder, String item, int bid): take (item, formal highbid, formal highbidder); if (bid > highbid) write (item, bid, bidder) else write (item, highbid, highbidder) How well would this work?
Factorial Setup: for (int i = 1; i <= n; i++) write (i); repeat n – 1 times: start FactTask FactTask: take (int i); take (int j); write (i * j); Eventually, tuple space contains one entry which is the answer. What if last two elements are taken concurrently? Better way to order Setup?
Finishing Factorial Setup: for (int i = 1; i <= n; i++) write (i); write (“workleft”, n - 1); take (“workleft”, 0); take (result); FactTask: take (“workleft”, formal w); if (w > 0) take (int i); take (int j); write (i * j); write (“workleft”, w – 1); Opps – we’ve sequentialized it!
Concurrent Finishing Factorial Setup: repeat n-1 times: start FactWorker out (“done”, 0); for (int i = 1; i <= n; i++) { write (i); if i > 1 write (“work”); } take (“done”, n-1); take (result); FactWorker: take (“work”); take (formal int i); take (formal int j); write (i * j); take (“done”, formal int n); write (“done”, n + 1);
Sorting in Linda • Problem: Sort an array of n integers • Initial tuple state (“A”, [A[0], ..., A[n-1]]) • Final tuple state: (“A”, [A’[0], ..., A’[n-1]]) such A’ has a corresponding element for every element in A, and for all 0 <= j < k <= n-1, A’[j] <= A’[k] Challenge Problem (50 bonus points)
Mars Pathfinder Landed on Mars, July 4, 1997 Sojourner Rover
New York Times, 15 July 1997 Mary Beth Murrill, a spokeswoman for NASA's Jet Propulsion Laboratory, said transmission of the panoramic shot took “a lot of processing power.” She likened the data overload to what happens with a personal computer “when we ask it to do too many things at once.” The project manager, Brian Muirhead, said that to prevent a recurrence, controllers would schedule activities one after another, instead of at the same time. It was the second time the Pathfinder's computer had reset itself while trying to carry out several activities at once. In response, controllers reprogrammed the computer over the weekend to slow down the rate of activities and avoid another reset. But today, about an hour into a two-hour transmission session, it happened again.
Priority-Based Scheduling • Scheduler ensures that the highest priority task that can run is always running • Lower priority tasks run only when no higher priority task can run Standard JavaVM scheduler does not do this, but many operating Systems for embedded systems do including the vxWorks used on the PathFinder. What can go wrong with priority-based scheduling?
Priority Inversion Low High Medium synchronized(r) synchronized(r) Pre-empts low-priority thread Waiting on lock r (held by low-priority task)
Priority Inversion on Mars Meterological data task (low priority) Bus Management Task (high priority) Data collection task (medium priority) For details, see http://research.microsoft.com/~mbj/Mars_Pathfinder/Authoritative_Account.html
Solutions? • Priority Inheritance • If a low priority task holds a resource needed by a high priority task, the low priority task temporarily inherits the high task’s priority • Priority Ceilings • Associate minimum priorities with resources
As suspected, the Pathfinder computer, struggling with several activities at once, reset itself each time it could not carry out low-priority tasks in the allotted time. A reset is a safety feature similar to hitting a reset button on a home computer. The low-priority task that kept tripping it up was the transfer of temperature and wind measurements from sensors to an electronics board and then into the computer. The solution is to raise the task's priority through some reprogramming, Mr. Muirhead said.
Charge Thread work = new Thread (ps5); work.setPriority (Thread.MAX_PRIORITY); work.start ();