Concurrent programming for dummies (and smart people too) - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Concurrent programming for dummies (and smart people too)

Description:

Concurrent programming for dummies (and smart people too) Tim Harris & Keir Fraser ... notifyAll()' should be used in place of notify()' for liveness ... – PowerPoint PPT presentation

Number of Views:47
Avg rating:3.0/5.0
Slides: 15
Provided by: labo161
Category:

less

Transcript and Presenter's Notes

Title: Concurrent programming for dummies (and smart people too)


1
Concurrent programming for dummies (and smart
people too)
Tim Harris Keir Fraser
2
Example hashtable
  • Where should the locking be done?

Hashtable object
Chains of key,value pairs
Array of buckets
3
Example single-cell buffer
int result if (!this.full) wait()
result this.val this.full false
notify() return result
if (this.full) wait() this.full true
this.val val notify()
void put(int val)
int get()
  • Methods should be marked as synchronized
  • wait() can wake up spuriously so must be in a
    loop
  • notifyAll() should be used in place of
    notify() for liveness

4
Conditional critical regions in Java
void put(int val) atomic (!this.full)
this.full true this.val val
int get() int result atomic (this.full)
this.full false return this.val
  • Basic syntax atomic (cond) statements
  • Execute the statements exactly once
  • starting in a state where the condition is true
  • The statements can access fields local
    variables, invoke methods, instantiate objects
    etc.

5
Implementation overview
Source code
Bytecode extended attributes
Software transactional memory operations
Machine code instructions
6
Implementation overview (ii)
  • Native STM interface
  • Transaction management
  • void STMStartTransaction(void)
  • boolean STMCommitTransaction(void)
  • void STMAbortTransaction(void)
  • Blocking
  • void STMWait(void)
  • Data access
  • word_t STMReadValue(addr_t a)
  • void STMWriteValue(addr_t a, word_t w)

Exposed as static methods
Called from interpreter / JITd code
7
Heap structure
Data storage
8
Non-contended updates
  • Acquire exclusive access to each ownership record
    needed
  • Check that they hold the correct versions
  • Set status to committed/aborted
  • Make updates to the heap (if needed)
  • Release ownership records, updating the versions

?
?
?
t1
a1
version 42
version 43
100
Status ACTIVE
Status COMMITTED
777
a1 (100,42) -gt (777,43)
a5 (200,17) -gt (888,18)
200
a5
version 17
888
version 18
?
?
9
Contended updates
  • Simple option
  • Spin waiting for the owner to make its updates
    and release
  • Obstruction-free option
  • Make updates on owners behalf and then releases
    ownership
  • Intricate first thread may make updates at a
    later stage. Introduces active updaters count
    into each orec details in the paper
  • Hacky option
  • Suspend the current owning thread
  • Make their updates
  • Revoke their ownership
  • Change their PC to be outside the commit
    operation
  • Resume the thread

10
Compound swaps
27
37
17
µs per operation
CPUs (1 thread per CPU)
11
Compound swaps (ii)
µs per operation
CPUs (1 thread per CPU)
12
Memory management
  • Two problems management of transaction
    descriptors management of shared data
    structures reachable from them
  • So-called A-B-A problems occur in most
    CAS-based systems
  • Weve looked at a number of schemes
  • Safe memory re-use (Michael)
  • Repeat offender problem (Herlihy et al)
  • Reference counting
  • Epoch-based schemes
  • In many cases were really allocating fresh
    pointers rather than needing more memory

a1
a5
13
Memory management (II)
  • Our more recent STM introduces a Hold/Release
    abstraction
  • A Hold operation acquires a revocable lock on a
    specified location
  • A Release operation relinquishes such a lock
  • A lock is revoked by a competing hold or by
    another thread writing to a held location
  • Revocation is exposed by displacing the previous
    owner to a specified PC
  • This lets us ensure only one thread at a time is
    working on a given transaction descriptor MM
    much simplified
  • Software implementation using mprotect or /proc

a1
a5
14
Future directions
  • Evaluation beyond synthetic benchmarks
  • Try the C STM interface yourself download under
    a BSD-style license from http//www.cl.cam.ac.uk/n
    etos/lock-free
  • Reflective exposure of a transactional API
  • Create, enter, leave transactions
  • Possibly enables better I/O handling
  • Opportunities for new hardware instructions
Write a Comment
User Comments (0)
About PowerShow.com