The standard does not guarantee a round trip int->void*->int conversion. It just happens to work on most desktop systems and so I used it as shortcut for passing a int by-value to the thread function.
Once you understand the rest of the code and why it works, you should be able to complete your assignment. Let us know if you need any of it explained.
gg
Cheers man. I can kind of follow it but can't really get my head around applying it to my assignment. I have until 18.00 tomorrow UTC time so late night tonight haha
I've just been told I can only use signals in this assignment so back to square one if anyone has any advice??
What kind of "signals"? As in <signal.h>, sigaction, etc? If so, that doesn't make sense if using pthreads. Are you supposed to be using fork() instead of pthreads?
gg
I'm supposed to use signal handler and sigset etc.. Here's the requirements..
You are to write a C program that prints the sum of each pair of integers in a text file. (The file whose contents are to be printed is supplied as a command line parameter.) Your program must function as follows:
- One thread (the reader) reads a pair of integers from the input file and prints them to the screen.
- Another thread (the calculator) then sums the numbers just loaded by the reader and prints the result to the screen.
- The reader blocks while waiting for the calculator to print the latest result.
- The calculator blocks while waiting for the reader to submit a pair of integers for addition.
- Before reading the next pair of integers from the file, the reader sleeps for a random number of microseconds (up to 10000).
- After summing the latest two integers loaded by the reader, the calculator sleeps for a random number of microseconds (up to 10000).
- A main thread coordinates the actions of the reader and calculator threads.
- Unix signals are used for inter-thread communication and to avoid busy-waiting.
- The main thread cancels the other threads once the last pair of integers has been summed.
- Each cancelled thread prints out a farewell message as it exits.
I only seen in the FAQs that I can only use signals and not conditional cars or mutexes .. Glad to say I'm completely lost now..