12. www.istabg.orgwww.vmware.com
Example 2: BoundedBuffer
Producer 1
Producer 2
Producer 3
Producer N
Consumer 1
Consumer 2
Consumer M
…
…
• safety:
– If empty, must not allow Get(); If full, must not allow Put()
• liveness (quiz#2):
– Put() on empty and Get() on full will eventually be allowed
14. www.istabg.orgwww.vmware.com
How to test for synchronization issues?
• Load/Stress testing (blackbox, whitebox)
• Specific interleavings testing (whitebox)
• All interleavings testing (whitebox)
• Instrumentation (blackbox)
20. www.istabg.orgwww.vmware.com
• Based on internal clock
– Tick increases when all threads are blocked
– waitForTick(tick) – blocks the thread until tick reaches
certain value
– assertTick(tick) – asserts the current tick
MultithreadedTC
26. www.istabg.orgwww.vmware.com
• Two threads only – Main and Secondary
• By default: For each line of Main thread (T1) ->
block and execute fully Secondary thread (T2)
ThreadWeaver
T1: Block A
T1: Block B
T2: Block 1
T2: Block 2
T1: Block A
T1: Block B
T2: Block 1
T2: Block 2
T1: Block A
T1: Block B
T2: Block 1
T2: Block 2
27. www.istabg.orgwww.vmware.com
• Two threads only – Main and Secondary
• By default: For each line of Main thread (T1) ->
block and execute fully Secondary thread (T2)
• Powerful Breakpoints
ThreadWeaver
32. www.istabg.orgwww.vmware.com
JavaPathFinder
Model Checking with JavaPathFinder
Image source: http://javapathfinder.sourceforge.net/events/JPF-workshop-050108/tutorial.ppt
OK
Code
properties
Model Checking
error trace
Line 5: …
Line 12: …
…
Line 41:…
Line 47:…
44. www.istabg.orgwww.vmware.com
• org.ista2011.multithreaded.common
– Several implementations of AccountManager, Counter, BounderBuffer and
MultipleReadersSingleWriter
• org.ista2011.multithreaded.executorservice
– Load/stress tests using ExecutorService
• org.ista2011.multithreaded.testng
– Load/stress tests using TestNG
• org.ista2011.multithreaded.mtc
– MultithreadedTC tests
• org.ista2011.multithreaded.imunit
– IMUnit tests
• org.ista2011.multithreaded.threadweaver
– ThreadWeaver tests
Source code packages (1)
45. www.istabg.orgwww.vmware.com
• org.ista2011.multithreaded.javapathfinder
– JavaPathFinder examples
• ca.mcgill.sable.racer
– RacerAJ source code
• org.ista2011.multithreaded.aspectj
– Custom aspect that increase the chance of hitting multithreading problem
during testing
• org.ista2011.multithreaded.blockbox.*
– Rest based AccountManager client/test and server (in .server package)
Source code packages (2)