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

  1. Create a small program, thread_demo, that does the following:
    1. From thread_demo.cs main function, create a loop that spawns 5 threads with integer arguments 0 through 4.
    2. 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.
    3. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!