DOC PREVIEW
UMD CMSC 433 - Finding Bugs in Concurrent Software

This preview shows page 1-2-3-4-5-6 out of 19 pages.

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

Unformatted text preview:

Finding Bugs in Concurrent SoftwareCMSC 433Fall 2006Options• Static analysis• Normal testing– hard to set up tests, results notreproducible• stepwise controlled testing• Dynamic data race detectionOne Place Bufferpublic class OnePlaceBuffer<T> {T value;synchronized public void put(@NonNull T v) {if (v == null) throw new NullPointerException();while (value != null) wait();value = v;notifyAll();}synchronized public @NonNull T get() {while (value == null) wait();T result = value;value = null;notifyAll();return result;}}Testing• At a minimum, we want full branchcoverage– we probably want to test situations whilewhile loops execute 2+ times as wellMultithreaded test caseclass MyTest extends MultithreadedTestCase { OnePlaceBuffer<String> buf; public initialize() { buf = new OnePlaceBuffer<String>(); } public void thread1() { buf.put(“a”); } public void thread2() { assertEquals(“a”, buf.get()); } }class MyTest extends MultithreadedTestCase { OnePlaceBuffer<String> buf; public void initialize() { buf = new OnePlaceBuffer<String>(); } public void thread1() { buf.put(“a”); } public void thread2() { Thread.sleep(1000); buf.put(“b”); } public void thread3() { Thread.sleep(2000); assertEquals(“a”, buf.get()); } public void thread4() { Thread.sleep(3000); assertEquals(“b”, buf.get()); }}What to do?• Making code depend upon sleep andtiming is yucky– doesn’t scale– doesn’t work in debugger– doesn’t always work• Introduce new idea– a metronome timer for thread test casesMetronome timer• Timer starts at zero• Advances only when all threads areblocked• Threads can wait until the timer reachesa particular value• Threads can query the current value ofthe timerOne place buffer example• Let’s figure out the timing/ticks for a testcase where two threads try to putsomething before any thread tries toremove somethingput(“a”)put(“b”)get()get()Thread 1 Thread 2 Thread 3 Thread 4Tick0123Running a test case• TestFramework.runOnce( new MyMTTestCase())• will run the test case once• TestFramework.runManyTimes( new MyMTTestCase(),42)• will run the test case 42 timesMore details on setting up amultithreaded test case• initialize() method is executed• all void thread…() methods are run,each in a separate thread• finish() method is executed• Class extends junit Assert class, so allthe assertXXX(…) methods areavailableTesting with metronomeclass MyTest extendsMultithreadedTestCase {OnePlaceBuffer<String> buf;public void initialize() { buf = new OnePlaceBuffer<String>();}public void thread1() { buf.put("a"); assertEquals(0,getTick());}public void thread2() { waitForTick(1); buf.put("b"); assertEquals(2,getTick());}public void thread3() { waitForTick(2); assertEquals("a", buf.get()); assertEquals(2,getTick());}public void thread4() { waitForTick(3); assertEquals("b", buf.get()); assertEquals(3,getTick());}}Runtime tools• You can use various tools to performdynamic instrumentation and testing forconcurrency:– data race detection– introduce additional thread interleavingPreventing Data Races• One programming technique to prevent races:– Ensure that for every shared field x, there is somelock L such that no thread accesses x withoutholding lock L• Note: This is not the only way to avoid races– There are fancier, more complicated techniques– But this is what you should do for your projectDetecting Races withcheckSync• Algorithm– Locks_held(t) = set of locks held by thread t– For each shared field x, C(x) := { all locks }– On each access to x by thread t,• C(x) := C(x) 󲰐 locks_held(t)• If C(x) = 󲰖 then issue a warning– From Savage et al, “Eraser: A Dynamic Race Detector forMultithreaded Programs,” TOCS 1997An Improvement• Unsynchronized r eads of ashared location are OK– As long as no one write s tothe field after it becomesshared• Track state of each field– Only enforce lockingprotocol when it becomesshared and writtenCheckSync• added a new file to your project 2distribution:– lib/checkSync.jar• add -javaagent:lib/checkSync.jar to yourJVM arguments to use checkSyncWhat checkSync does• Instruments your code to apply theeraser protocol• throws an exception if an accessviolates it– use -javaagent:lib/checkSync.jar=keepGoingto force it to keep going, printing error logto sync.log– use =report to get a report on all fieldsprinted to


View Full Document

UMD CMSC 433 - Finding Bugs in Concurrent Software

Documents in this Course
Trace 1

Trace 1

62 pages

Reflection

Reflection

137 pages

Testing

Testing

25 pages

Paradigms

Paradigms

10 pages

Testing

Testing

17 pages

Java RMI

Java RMI

17 pages

Java RMI

Java RMI

17 pages

Java RMI

Java RMI

17 pages

Trace 1

Trace 1

46 pages

Jini

Jini

4 pages

Final

Final

15 pages

Java RMI

Java RMI

13 pages

Testing

Testing

16 pages

Load more
Download Finding Bugs in Concurrent Software
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Finding Bugs in Concurrent Software 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 Finding Bugs in Concurrent Software 2 2 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?