What’s wrong with my program?

My issue: My program does not work for the input of 1,000,000 and I am not sure what I’m doing wrong. When I try to input 1,000,000 it stops at around 180,000

Write a C program that will create threads (Prime Thread and Print Thread) that will find and print the prime numbers between 0 and an integer number that the user provides. There is no limit on the number of threads and you can create as many threads as you need.

The prime numbers will be stored in a shared buffer named “Prime”. The threads will take turns between finding the prime numbers and printing the found numbers.

The main will get a number from the user and store it in a variable named “Max_Num” and will create the threads (Prime Thread and Print Thread) to find and print the prime numbers.

Prime Thread and Print Thread

The Prime threads will find the prime numbers and will store them in a global shared variable “Prime”. The Prime threads will continue to produce prime numbers until the buffer is full then will wait until the Print threads empty the buffer and print it to the screen.

You can use any synchronization technique (lock, mutex, semaphore) we discussed in class. You may need to use a Mutex lock “Lock_Prime” to ensure that only one thread accesses the “Prime” buffer at a time. Your program should run reasonably fast for any given number.

-Your program should be able to adjust the number of threads according to the input size.

-You can use any synchronization technique. Code must be well documented with plenty of comments.

-Your code should work correctly with any input.

-While some delay is accepted, results should be ready within a reasonable time.

-Your program should be able to accept inputs of 10000, 100000, and 1000000. For 1000000 a reasonable execution time is < 5 minutes.

– The waiting for the completion of threads should occur at the end i.e. threads need to be created before any of the joining happens.

– The program should print the amount of prime numbers within the given range, as a check

Example: N = 10

Acceptable: 2,3,5,7 3,2,5,7 5,7,2,3

Not Acceptable: 2,2,3,5,7 2,3,5

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
The price is based on these factors:
Academic level
Number of pages
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more
error: Content is protected !!