Threads, Pipes Eratosthenes' Sieve

CLOSED
Bids
8
Avg Bid (USD)
$133
Project Budget (USD)
$30 - $250

Project Description:
Hey, in need of a project in 6 hours?


Threads, Pipes
Eratosthenes' Sieve


Eratosthenes' sieve is a method for generating prime numbers. Our goal is to implement it using threads and pipes. The task may occur difficult to do at once, so it is divided into several steps.


--------------------------------------------------------------------------------

[10 p.]
Here is the algorithm:

A thread named Generator generates consecutive natural numbers (> 1) (until it reaches the limit given as argument) and writes them to a pipe.
The numbers are received by another thread named Sieve, created by the generator.
The sieving thread stores the first number read from the pipe. It is a prime number.
Afterwards it creates new sieving thread and transfers to it (using another pipe) the rest of the received numbers except for numbers divisible by the stored prime number.
Then the sieving thread returns (using another pipe) the stored prime number to the thread, from which it received the numbers.
Next, the sieving thread reads prime numbers from the (another, not used yet) pipe connecting it and the sieving thread it created earlier and sends them to its parent (the thread, to which the stored prime was sent; it is the thread, that created this one).
Having generated all the natural numbers, the main thread - the Generator - starts reading prime numbers from the pipe connecting it and its descendant and writes them to the command prompt.


--------------------------------------------------------------------------------

Step 1
Create the class Generator. An object of this class is a thread generating integer numbers (>1).


--------------------------------------------------------------------------------

Step 2
Create the class Sieve. An object of this class is a thread reading numbers from the pipe connecting it to the generator.


Notes:
A stream object must be passed to the receiver thread as an argument to a constructor.
A pipe stream must be decorated with a data stream (DataOutputStream or DataInputStream) to enable transfer of primitive types (integers).
Having printed all the received numbers, both threads should terminate cleanly. To achieve this, the special value 0 may be sent as a termination signal (EOD, end of data).


--------------------------------------------------------------------------------

Step 3
The receiver thread passes all the received numbers back to the sender using another pipe.
The sender (the generator) prints them out to the command prompt.


--------------------------------------------------------------------------------

Step 4
The sieving thread creates another sieving thread and transfers to it all the numbers it has received.
The created sieving thread (descendant) reads the numbers and sends them back to the sender immediately (using another pipe).
The sieving thread created by the generator receives the numbers from the descendant and returns them to the generator, who prints them.
There are 3 threads here.


--------------------------------------------------------------------------------

Step 5, the last
The sieving thread does not pass all the numbers it gets to the descendant. It passes only those of them that are not divisible by the first number it got (and stored).

Each sieving thread creates another sieving thread until there are any numbers left in the transferred sequence.

Besides the stored prime number, it passes to the parent thread all the numbers received from the descendant.


--------------------------------------------------------------------------------

Notes:
Each sieving thread must take 2 stream objects as arguments to its constructor (only in the final version).
All the streams must be closed properly.
Each thread should print lots of diagnostic messages to ease debugging. However, a correctly working program should print only the prime numbers.

Skills required:
Java
About the employer:
Verified
Public Clarification Board
Bids are hidden by the project creator. Log in as the employer to view bids or to bid on this project.
You will not be able to bid on this project if you are not qualified in one of the job categories. To see your qualifications click here.


$ 173
in 0 days
$ 149
in 2 days
Hire dimplex
$ 155
in 3 days
$ 55
in 2 days
$ 111
in 2 days
Hire sandeshghule
$ 155
in 3 days
Hire psenthilbuss
$ 155
in 3 days
Hire RahulKrishnan
$ 111
in 1 days