Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C Homework
Create C program that calculates prime numbers from a certain number X to a number Y. Modify the program so as to run two threads at the same time. The first thread will start counting from X to Y and the second from Y to Z
Posted 26-Jan-13 7:45am
Edited 26-Jan-13 7:50am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This looks like homework.
 
It would be best if you did your own homework. It is given to you so that you will learn something, think about what have been taught. Read your text books and give it a try.
 
Some resources to help you:
Prime number[^]
C multi-threading search[^]
 
Once you have code and run into problems you can always come back here with a more specific question and the community will do its best to help you. Don't forget to post only the relevant code bits that pose the problem as a code dump is not usually helpful at all in getting someone to help/assist you.
 
Good luck and happy coding.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

That sounds like a bad homework assignment.
Look into Sieve of Eratosthenes. I don't think it lends itself to multi-threading though.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

The example code at this[^] article does a multi-threaded sieve of Eratosthenes using the actor programming model. It is C++ though (not C). By changing the number of primes handled by each thread, you can control the number of threads (ie. restrict to 2).
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 325
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 Sergey Alexandrovich Kryukov 189
0 OriginalGriff 5,455
1 DamithSL 4,422
2 Maciej Los 3,860
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,010


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 26 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100