Question: Create a small program, thread_demo, that does the following: From thread_demo.cs main function, create a loop that spawns 5 threads with integer arguments 0 through
- Create a small program, thread_demo, that does the following:
- From thread_demo.cs main function, create a loop that spawns 5 threads with integer arguments 0 through 4.
- The threads entry point, in file worker.c, is function void worker(void *) where void * is expected to be a pointer to an int. The thread computes and prints the square of the argument, then returns.
- The main thread should wait until all threads have completed, then print work complete.
Be sure to create a makefile. You are expected to use the POSIX thread interface for this assignment. The FAQ has an example of creating POSIX threads and waiting for a thread to terminate can be done with pthread_join (see the man page or read the materials on threads on Blackboard).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
