Hi , i am very new to threads.. need help to build the following program.
Please if possible provide me the program.
The program should be in C language working in Linux operating systems.
Q) Execute a program using any thread library to create the number of threads specified by the user; each thread independently generates a random integer as an upper limit and then computes and prints the number of primes less than or equal to that of upper limit along with that upper limit.
Try it yourself first. If you get stuck then show what you have done and we can point you in the right direction.
What kind of assignment is this? There's no need for mutexes, no need to develop any communication between the threads.... This is the dumbest threads assignment I've ever seen in my life.
That said, if you can compute the number of primes, this is easy. Write a function to compute the primes, then write a function that complies with (I'm choosing pthread here) the pthread_create prototype (it'd be void *thread_fn(void *arg) ) and from that function call the primes function. Then, in main call pthread_create passing thread_fn as the start_routine argument.
If you need more than that then man pthread_create . No one here is going to write the primes function for you, though. However a simple version is very easy and I'm sure you can google for it.