Click here to Skip to main content
12,953,014 members (61,199 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 6:45am
Updated 26-Jan-13 6:50am
Rate this: bad
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.
Rate this: bad
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.
Rate this: bad
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).

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,920

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 26 Jan 2013
Copyright © CodeProject, 1999-2017
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