Threads

Due: 11:00pm, Tuesday, September 26, 2023

Get the Assignment Code

Login to your university Unix account and copy the assignment code to a location under your home directory:

  cp -r /export/home/public/schwesin/csc328/assignments/project3 LOCATION

where LOCATION is a directory of your choosing.

Description

For this project you will write a C program that creates 1 to 10 child processes using the pthread library.

Program Outline

I. Declare variables

  1. Process command line arguments
  1. Initialize the variables declared in part I.
  1. Create threads

V. End the program

Thread Processing

The main thread must:

Each sub-thread must do the following:

  1. Print the following information: the text string “BEFORE increment”, thread number, thread ID, value of X, value of num, and value of nump.

  2. Add 50 to the value of X.

  3. Increment the value of num.

  4. Increment the value that nump points to.

  5. Print the following information: the text string “AFTER increment”, thread number, thread ID, value of X, value of num, and value of nump.

  6. End the thread.

The print statements for a sub-thread should follow this format assuming the command line arguments for X, num, and nump are 500, 5, and 10 respectively. (note some of the values may be different):

BEFORE increment: Thread number 1 with TID of 3795580672: X = 500, num = 5, nump = 10
AFTER increment: Thread number 1 with TID of 3795580672: X = 550, num = 6, nump = 11

Makefile Rules

The following rules must be added to the provided Makefile:

Turning in the Assignment

To turn in the assignment, execute the submit script by running the command

  make submit

from within the project3 directory.

Grading Criteria