of 1

Compile and run the program on a Linux system. Find out what results it produces and explain the results. Compile as follows:

Published on June 2018 | Categories: Self-Help | Downloads: 25 | Comments: 0
172 views

This program creates a new thread. Both the main thread and the new thread then increment the variable counter 20 times. But the program itself produces some unexpected results. 1. Compile and run the program on a Linux system. Find out what results it produces and explain the results. Compile as follows: $ gcc thread2.c -o thread2 -lpthread Run using the following command $ ./thread2 2. Modify the program so that the variable counter has a value of 40 when the program ends. Hint: use synchronization primitives. Please submit a zip file labelled as Assignment4_Yourname.zip. It should include a PDF file with explanation of the results and a C source file with the modified program. Clarification: One some systems, you might not see the unexpected result right away. In that case, run the program several times and see if you get any unexpected results. If you still don't see anything, insert some sleep statements into both the thread functions and manually study the code and point out what's wrong with the code. Download Attachment: assignment4.c.rtf Additional Requirements Level of Detail: Show all work Other Requirements: Study the example program in the attached file. This program creates a new thread. Both the main thread and the new thread then increment the variable counter 20 times. But the program itself produces some unexpected results. 1. Compile and run the program on a Linux system. Find out what results it produces and explain the results. Compile as follows: $ gcc thread2.c -o thread2 -lpthread Run using the following command $ ./thread2 2. Modify the program so that the variable counter has a value of 40 when the program ends. Hint: use synchronization primitives.

Comments

Content

This program creates a new thread. Both the main thread and the new thread then increment the variable counter 20 times. But the program itself produces some unexpected results. 1. Compile and run the program on a Linux system. Find out what results it produces and explain the results. Compile as follows: $ gcc thread2.c -o thread2 -lpthread Run using the following command $ ./thread2 2. Modify the program so that the variable counter has a value of 40 when the program ends. Hint: use synchronization primitives. Please submit a zip file labelled as Assignment4_Yourname.zip. It should include a PDF file with explanation of the results and a C source file with the modified program. Clarification: One some systems, you might not see the unexpected result right away. In that case, run the program several times and see if you get any unexpected results. If you still don't see anything, insert some sleep statements into both the thread functions and manually study the code and point out what's wrong with the code. Download Attachment: assignment4.c.rtf Additional Requirements Level of Detail: Show all work Other Requirements: Study the example program in the attached file. This program creates a new thread. Both the main thread and the new thread then increment the variable counter 20 times. But the program itself produces some unexpected results. 1. Compile and run the program on a Linux system. Find out what results it produces and explain the results. Compile as follows: $ gcc thread2.c -o thread2 -lpthread Run using the following command $ ./thread2 2. Modify the program so that the variable counter has a value of 40 when the program ends. Hint: use synchronization primitives.

Sponsor Documents


Recommended

No recommend documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close