Title: Reactive Multiword Synchronization for Multiprocessors
1Reactive Multi-word Synchronization for
Multiprocessors
- Phuong Hoai Ha
- Philippas Tsigas
PACT 03, New Orleans, Louisiana Sept. 27th
Oct. 1st, 2003
2Overview
- Motivation
- Synchronization primitives in hardware or in
software ? - Lock-free synchronization
- Previous works
- Recursive helping policy
- Software transactional memory
- Our contributions
- Reactive multi-word compare-and-swap operations
- Results
- Conclusion
3Hardware or Software ?
- Programmers need high-level synchronization
operations - multi-word read-modify-write
- Hardware systems can support only a limited
number of synchronization primitives - single-word primitives
synchronization primitives
4Hardware synch. primitives
- A common hardware synchronization primitive used
in implementing concurrent data structures is
compare-and-swap.
- compareswap( w, old, new)
- atomically
- if( w old)
- w ? new
- return( true)
-
- else return( false)
-
5Lock-free synchronization
- Lock-free implementations guarantee that always
at least one operation will progress.
- Example
- counter0
- Increment()
- t counter
- counter t 1
- return t
-
Thread 1
Result 0
Thread 2
Result 0 ?
6Example (cont.)
- counter0 lock free
- Increment()
- while( testset( lock, busy) ! free)
//synchronization point - t counter
- counter t 1
- release( lock)
- return t
-
Result 0
Thread 1
waiting
Thread 2
Result 1 ?
7Example (cont.)
crash
Thread 1
wait forever
Thread 2
- counter0
- Increment()
- do
- t counter
- new t 1
- while( !compareswap( counter, t, new))
//lock-free - return t
8Is CAS handy enough ?
- Example inserting cells and deleting cells from
linked list data structure occur concurrently
t1
t2
? The cell C has not been inserted correctly
9Overview
- Motivation
- Synchronization primitives in hardware or in
software ? - Lock-free synchronization
- Previous works
- Recursive helping policy
- Software transactional memory
- Our contributions
- Reactive multi-word compare-and-swap operations
- Results
- Conclusion
10Multi-word compareswap Specifications
- CASN Atomic read-modify-write to a set of
locations -
- CASN( ( x1, a1, b1), ( x2, a2, b2), , ( xn,
an,bn) ) - atomically
- if( ( x1 a1) ( xn an)) x1 b1
xn bn return( true) - else return( false)
-
- Useful building blocks in the implementations of
concurrent data structures - Many existing designs (queue, stack, etc.) use
CAS2 directly - A higher abstraction like transactions is
provided
11Methods
- Requirements
- Non-blocking
- Low contentions
? Use locks again! How non-blocking is it ?
12Helping technique
- All threads write down in shared variables what
they are doing - Whenever ti needs a location already locked by
tj, ti helps tj complete its own work - Recursive helping policy (A. Israeli et al)
4
5
3
6
7
8
2
1
...
words
T1( 1, 2, 3, 4)
help T2
T2( 3, 6, x, x)
help T3
T3( 6, 7, 8, x)
13Helping technique (cont.)
- Software transactional memory (N. Shavit et al)
4
5
3
6
7
8
2
1
9
...
words
T1( 1, 2, 8, x)
help T2
T2( 2, 3, 5, 6)
T3( 6, 7, 8, 9)
14Overview
- Motivation
- Synchronization primitives in hardware or in
software ? - Lock-free synchronization
- Previous works
- Recursive helping policy
- Software transactional memory
- Our contributions
- Reactive multi-word compare-and-swap operations
- Results
- Conclusion
15Reactive CASN
CASNs
RCASN states
RCASN data structure
16Reactive CASN illustration
? word
? conflict
?
?
?
?
?
?
?
?
?
?
17First RCASN
When to move back?
- How to calculate the threshold?
- Mapping
- ri blockedi / kepti average contention
- blockedi ? 1, P-2, kepti ? 1, N-1
- Threshold r sqrt( (P-2) / (N-1))
- Competitive ratio c sqrt((P-2)(N-1))
- Advantages
- Reduce contentions
- Favor RCASNs
- closer to completion
- with a small number of conflicts
18Second RCASN
When and how far to move back?
Rules (c.f. thread-based algorithm)
- Advantages
- Reduce contentions
- Favor to release words with high contention.
19Results from our experiments
20Conclusions
- We have presented two reactive, lock-free
multi-word compare-and-swap that - Measure in an efficient way the contentions on
the words, - Reactively decide whether and how many words need
to be released, - Promote the CASN operations with high probability
of success, - Are competitive and run fast.
- Future work
- Look into new reactive schemes that allow faster
reaction and better execution time. - Incorporate the algorithms in the NOBLE, a
library of non-blocking synchronization
protocols. - http//www.noble-library.org
21Thank you!