COS226 - Lecture - Introduction - 1

# COS226 - Lecture - Introduction - 1 -...

This preview shows pages 1–7. Sign up to view the full content.

COS226: Concurrent Systems Chapter 1: Introduction Part 1

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

View Full Document
Find all the primes between 1 and 10 10 Two problems: Many primes between 1 and 10 9  but hardly any  between 9 . 10 9  and 10 10 ; Larger primes take longer to verify.
void primePrint { int i = ThreadID.get(); int block = power(10, 9); for (int j = (i * block) + 1; j <= (I + 1) block; j++) { if (isPrime(j)) print(j); } }

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

View Full Document
Counter counter = new Counter(1); void primePrint { long i = 0; long limit = power(10, 10); while (i < limit) { i = counter.getAndIncrement(); if (isPrime(i)) print(i); } }
public class Counter { private long value; public Counter(long I) { value = i; } public long getAndIncrement() { return value++; } }

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

View Full Document
getAndIncrement() return value++; long temp = value; value = temp + 1; return temp;
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 / 12

COS226 - Lecture - Introduction - 1 -...

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

View Full Document
Ask a homework question - tutors are online