COS226 - Lecture - Introduction - 1

COS226 - Lecture - Introduction - 1 -...

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

View Full Document Right Arrow Icon
    COS226: Concurrent Systems Chapter 1: Introduction Part 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
    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.
Background image of page 2
    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); } }
Background image of page 3

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

View Full DocumentRight Arrow Icon
    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); } }
Background image of page 4
    public class Counter { private long value; public Counter(long I) { value = i; } public long getAndIncrement() { return value++; } }
Background image of page 5

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

View Full DocumentRight Arrow Icon
    getAndIncrement() return value++; long temp = value; value = temp + 1; return temp;
Background image of page 6
Image of page 7
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 Right Arrow Icon
Ask a homework question - tutors are online