I read through the text, and I didn't see anything about not sharing variables.
But, if you really don't want to share variables, well, I would have each thread create a linked list for each prime number it finds. Add a link to the head of the list to the struct that you pass by reference into the thread functions. Then when all three (or four) threads finish, you will have three linked lists of all of the prime numbers in that area.
This however assumes that you know how to handle linked lists in C.
|