Project #40240 - C Programming

You are to write a C program that will produce a list of N prime numbers, where N is specified on the command line. Your program must use threads so that P prime number candidates are always being considered, one by each of P threads. The number of threads, P, is an optional command line argument and will appear second (last) on the command line if at all. If P is not given on the command line, a default value of 3 should be used.

When a thread determines that the candidate is prime, it must atomically place it in the list of prime numbers. This must be done in a critical section lest another thread try to add another candidate at the same time. Regardless of whether a candidate is prime, threads must also coordinate getting the next candidate to consider for primality, which means that this too resides in a critical section. As soon as N primes have been found, all other threads should be terminated and the list of primes printed. Your program should incorporate principles of good design, including minimizing the time spent within critical sections. You may use your choice of algorithm for determining the primality of a candidate.

You are responsible for creating your own test data. It's a good idea to create your test cases first, building upon your test data, as this will help you with your development. Be sure to include a variety of "corner cases" to ensure that your program doesn't work for only "normal" data. Test driven development (TDD) is a good practice that you should cultivate.

 

When testing, be sure to use lots of different examples. In particular, if the value of N given on the command line is negative or zero. Your program should be reasonably robust.

 

As always, be sure to use good indentation, descriptive constant, variable, type, function, procedure, and class names. Use named constants when appropriate. Also use good commenting style, remembering that the first thing in any program file should be a comment that gives a brief overview of what the file contains (and should do). You might find these commenting guidelines helpful.

 

Subject Computer
Due By (Pacific Time) 09/16/2014 11:59 pm
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy