Chapter08Concurrency_4

Chapter08Concurrency_4 - Overview Introduction Spin Locks...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Distributed Systems Roger Wattenhofer 8/1 Small Systems Chapter 8 Distributed Systems Roger Wattenhofer 8/2 Overview Introduction Spin Locks – Test-and-Set & Test-and-Test-and-Set – Backoff lock – Queue locks Concurrent Linked List – Fine-grained synchronization – Optimistic synchronization – Lazy synchronization – Lock-free synchronization Hashing – Fine-grained locking – Recursive split ordering Distributed Systems Roger Wattenhofer 8/3 memory object object Concurrent Computation We started with… Multiple threads – Sometimes called processes Single shared memory Objects live in memory Unpredictable asynchronous delays In the previous chapters, we focused on fault-tolerance – We discussed theoretical results – We discussed practical solutions with a focus on efficiency In this chapter, we focus on efficient concurrent computation ! – Focus on asynchrony and not on explicit failures Distributed Systems Roger Wattenhofer 8/4 Example: Parallel Primality Testing Challenge – Print all primes from 1 to 10 10 •G i v e n – Ten-core multiprocessor – One thread per processor Goal – Get ten-fold speedup (or close) Naïve Approach – Split the work evenly – Each thread tests range of 10 9 10 9 10 10 2·10 9 1 P 0 P 1 P 9 Problems with this approach?
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Distributed Systems Roger Wattenhofer 8/5 Issues Higher ranges have fewer primes Yet larger numbers harder to test Thread workloads – Uneven – Hard to predict Need dynamic load balancing Better approach – Shared counter! – Each thread takes a number 17 18 19 Distributed Systems Roger Wattenhofer 8/6 Counter counter = new Counter(1); void primePrint() { l ong j = 0; while (j < 10 10 ) { j = counter.getAndIncrement(); if (isPrime(j)) print(j); } } Procedure Executed at each Thread Shared counter object Increment counter & test if return value is prime Distributed Systems Roger Wattenhofer 8/7 Counter Implementation public Class counter { private long value; public long getAndIncrement() { return value++; } } What’s the problem with this implementation? Distributed Systems Roger Wattenhofer 8/8 time value… 1 read 1 read 1 write 2 read 2 write 3 write 2 23 2 Problem
Background image of page 2
Distributed Systems Roger Wattenhofer 8/9 Counter Implementation public Class counter { private long value; public long getAndIncrement() { temp = value; value = temp + 1; return temp; } } These steps must be atomic! Recall: We can use Read-Modify- Write (RMW) instructions! We have to guarantee mutual exclusion Distributed Systems Roger Wattenhofer 8/10 Model The model in this part is slightly more complicated – However, we still focus on principles What remains the same ?
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/11/2010 for the course COS COS226 taught by Professor Klazar during the Spring '10 term at University of Pretoria.

Page1 / 41

Chapter08Concurrency_4 - Overview Introduction Spin Locks...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online