Professional Documents
Culture Documents
Lab 5 – Threads
- Read “Lab5-Lecture.pptx”.
- Finish below programs, compile and execute them.
- Submit to SAKAI in the end of lab hours.
1. Write a program that creates three threads that perform the following tasks:
- The first thread takes arguments from the environment (argv [1]), checks if the number is 0,
calculates the factorial of this number (can use struct or global variables).
- The second thread waiting for the first thread to complete, perform the calculation of the
number of words smaller than the result of the first factorial factor calculated.
- Third thread waiting for the second thread to complete, write the result into the file is the
second argument from the environment variable (argv [2]). The contents of the record include:
the first line stores the value of argv [1]; The second line stores the results of the factorial; The
third line stores the sum of smaller numbers than the factorial.