$20 Bonus + 25% OFF
Securing Higher Grades Costing Your Pocket?
Book Your Assignment at The Lowest Price
Now!
Students Who Viewed This Also Studied
CS431 Operating Systems Design
Task
1 Overview While multi-threaded applications offer a number of benefits over multi-process designs, they have one important limitation: Synchronizing threads’ access to shared data and preventing race con- ditions is the responsibility of the programmer. With processes, the kernel provides that synchro- nization. With threads, synchronization must be written into the program. In this programming assignment, you will practice using two synchronization primitives, semaphores and mutex locks, in a multi-threaded program using the pthread API.
2 Requirements Refer to the program code given in the file thread sync.c. Although the program does not perform any particularly useful tasks, it demonstrates some important concepts regarding threading. The program involves a large number of concurrent threads that will each write to and read from portions of a file at specific locations within it, effectively serving as a shared buffer to be synchronized. In the main program a total of 20,000 threads are created: 10,000 for writing; and 10,000 for reading. Note: if you find your computer too resource limited to manage that many threads, feel free to reduce that number appropriately. The threads that write to the file execute first, and the main program thread blocks in the mean- time. The threads that read from the file execute following all writer threads. Your job is to modify the two thread functions to implement synchronized reading and writing. Each writer thread will write a portion of the file at a designated offset into it using the pwrite system call. The reader threads will each read from the file at a similar file offset using the pread system call.
3 Synchronization This section describes the requirements for the thread functions for the reader and writer threads.
3.1 Writer Threads This is the function called by each writer thread. Each thread will take the following steps:
1. Place the thread’s ID number into the char array named buffer, that is already declared. The resulting character string must be exactly five characters in length. For this, consider using sprintf with a format specifier. If you place a number after the % in the format specifier, that indicates the minimum field width. If the resulting string happens to be less than the width, it will be filled with blank spaces. Refer to the sample file contents in Section 3.3.
2. Call wait on the semaphore. Refer to the man page for sem wait.
3. Acquire the mutex lock. Refer to the man page for pthread mutex lock.
4. Do a pwrite of the char array buffer on the file at the current file offset. Write exactly DATA SIZE, i.e., 5, bytes. Refer to the man page for pwrite for parameters and return type.
5. Increment the file offset value by DATA SIZE number of bytes.
6. Release the mutex lock. Refer to the man page for pthread mutex lock.
7. Call signal on the semaphore. Refer to the man page for sem post. Steps 4 and 5 constitute the critical section of the thread. The mutex lock (and therefore exclusive write access) is needed to write to the file and modify the variable representing the total offset into the file shared by all threads. However, the semaphore, initialized to 5, allows up to five threads at a time to contend for the mutex lock. All others will block.
3.2 Reader Threads This is the function called by each reader thread. Each thread will take the following steps:
1. Call wait on the semaphore. Refer to the man page for sem wait.
2. Acquire the mutex lock. Refer to the man page for pthread mutex lock.
3. Do a pread of the file at the current file offset. Read exactly DATA SIZE, i.e., 5, bytes. Refer to the man page for pread for parameters and return type.
4. Decrement the file offset value by DATA SIZE number of bytes.
5. Release the mutex lock. Refer to the man page for pthread mutex lock.
6. Call signal on the semaphore. Refer to the man page for sem post.
7. Output the result of the pread. Steps 3 and 4 constitute the critical section of the reader thread. The mutex lock is needed to read from the file and modify the shared variable representing the total offset into the file, as with the writer threads. Note that all writer threads execute first, followed by the reader threads. Your program should not have both reader and writer threads executing concurrently.
3.3 Program Output Once the program terminates
CS431 Operating Systems Design
Answer in Detail
Solved by qualified expert
Get Access to This Answer
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Hac habitasse platea dictumst vestibulum rhoncus est pellentesque. Amet dictum sit amet justo donec enim diam vulputate ut. Neque convallis a cras semper auctor neque vitae. Elit at imperdiet dui accumsan. Nisl condimentum id venenatis a condimentum vitae sapien pellentesque. Imperdiet massa tincidunt nunc pulvinar sapien et ligula. Malesuada fames ac turpis egestas maecenas pharetra convallis posuere. Et ultrices neque ornare aenean euismod. Suscipit tellus mauris a diam maecenas sed enim. Potenti nullam ac tortor vitae purus faucibus ornare. Morbi tristique senectus et netus et malesuada. Morbi tristique senectus et netus et malesuada. Tellus pellentesque eu tincidunt tortor aliquam. Sit amet purus gravida quis blandit. Nec feugiat in fermentum posuere urna. Vel orci porta non pulvinar neque laoreet suspendisse interdum. Ultricies tristique nulla aliquet enim tortor at auctor urna. Orci sagittis eu volutpat odio facilisis mauris sit amet.
Tellus molestie nunc non blandit massa enim nec dui. Tellus molestie nunc non blandit massa enim nec dui. Ac tortor vitae purus faucibus ornare suspendisse sed nisi. Pharetra et ultrices neque ornare aenean euismod. Pretium viverra suspendisse potenti nullam ac tortor vitae. Morbi quis commodo odio aenean sed. At consectetur lorem donec massa sapien faucibus et. Nisi quis eleifend quam adipiscing vitae proin sagittis nisl rhoncus. Duis at tellus at urna condimentum mattis pellentesque. Vivamus at augue eget arcu dictum varius duis at. Justo donec enim diam vulputate ut. Blandit libero volutpat sed cras ornare arcu. Ac felis donec et odio pellentesque diam volutpat commodo. Convallis a cras semper auctor neque. Tempus iaculis urna id volutpat lacus. Tortor consequat id porta nibh.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Hac habitasse platea dictumst vestibulum rhoncus est pellentesque. Amet dictum sit amet justo donec enim diam vulputate ut. Neque convallis a cras semper auctor neque vitae. Elit at imperdiet dui accumsan. Nisl condimentum id venenatis a condimentum vitae sapien pellentesque. Imperdiet massa tincidunt nunc pulvinar sapien et ligula. Malesuada fames ac turpis egestas maecenas pharetra convallis posuere. Et ultrices neque ornare aenean euismod. Suscipit tellus mauris a diam maecenas sed enim. Potenti nullam ac tortor vitae purus faucibus ornare. Morbi tristique senectus et netus et malesuada. Morbi tristique senectus et netus et malesuada. Tellus pellentesque eu tincidunt tortor aliquam. Sit amet purus gravida quis blandit. Nec feugiat in fermentum posuere urna. Vel orci porta non pulvinar neque laoreet suspendisse interdum. Ultricies tristique nulla aliquet enim tortor at auctor urna. Orci sagittis eu volutpat odio facilisis mauris sit amet.
Tellus molestie nunc non blandit massa enim nec dui. Tellus molestie nunc non blandit massa enim nec dui. Ac tortor vitae purus faucibus ornare suspendisse sed nisi. Pharetra et ultrices neque ornare aenean euismod. Pretium viverra suspendisse potenti nullam ac tortor vitae. Morbi quis commodo odio aenean sed. At consectetur lorem donec massa sapien faucibus et. Nisi quis eleifend quam adipiscing vitae proin sagittis nisl rhoncus. Duis at tellus at urna condimentum mattis pellentesque. Vivamus at augue eget arcu dictum varius duis at. Justo donec enim diam vulputate ut. Blandit libero volutpat sed cras ornare arcu. Ac felis donec et odio pellentesque diam volutpat commodo. Convallis a cras semper auctor neque. Tempus iaculis urna id volutpat lacus. Tortor consequat id porta nibh.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Hac habitasse platea dictumst vestibulum rhoncus est pellentesque. Amet dictum sit amet justo donec enim diam vulputate ut. Neque convallis a cras semper auctor neque vitae. Elit at imperdiet dui accumsan. Nisl condimentum id venenatis a condimentum vitae sapien pellentesque. Imperdiet massa tincidunt nunc pulvinar sapien et ligula. Malesuada fames ac turpis egestas maecenas pharetra convallis posuere. Et ultrices neque ornare aenean euismod. Suscipit tellus mauris a diam maecenas sed enim. Potenti nullam ac tortor vitae purus faucibus ornare. Morbi tristique senectus et netus et malesuada. Morbi tristique senectus et netus et malesuada. Tellus pellentesque eu tincidunt tortor aliquam. Sit amet purus gravida quis blandit. Nec feugiat in fermentum posuere urna. Vel orci porta non pulvinar neque laoreet suspendisse interdum. Ultricies tristique nulla aliquet enim tortor at auctor urna. Orci sagittis eu volutpat odio facilisis mauris sit amet.
Tellus molestie nunc non blandit massa enim nec dui. Tellus molestie nunc non blandit massa enim nec dui. Ac tortor vitae purus faucibus ornare suspendisse sed nisi. Pharetra et ultrices neque ornare aenean euismod. Pretium viverra suspendisse potenti nullam ac tortor vitae. Morbi quis commodo odio aenean sed. At consectetur lorem donec massa sapien faucibus et. Nisi quis eleifend quam adipiscing vitae proin sagittis nisl rhoncus. Duis at tellus at urna condimentum mattis pellentesque. Vivamus at augue eget arcu dictum varius duis at. Justo donec enim diam vulputate ut. Blandit libero volutpat sed cras ornare arcu. Ac felis donec et odio pellentesque diam volutpat commodo. Convallis a cras semper auctor neque. Tempus iaculis urna id volutpat lacus. Tortor consequat id porta nibh.
24 More Pages to Come in This Document. Get access to the complete answer.
More CS431 CS431 Operating Systems Design: Questions & Answers
C04403 Object Oriented Software Development
Task:
Brief
This assignment consists of four parts, you must work through them in order (start with design then attempt development etc).You must achieve a mark of at least 50% to pass this assignment.It is very important that you work on this coursework by yourself and do not let other …
View Answer
CIS006-2 Concepts and Technologies of Artificial Intelligence
Question:
1.Demonstrate results of using an established AI technique which is capable of finding a solution to a given AI problem represented by a data set
2.Identify the cases of correct and incorrect outcomes generated by the technique on the given data set
3.Evaluate the accuracy of the tech …
View Answer
MOD003264 Digital Security
Question:
Whilst your target audience has some level of IT knowledge, they have employed you as the subject expert. Answers to each question should be provided at a level of technical detail sufficient to that target audience in the given scenario. You should apply the knowledge gained from the&n …
View Answer
CTI 110 Web, Programming and Database Foundations
Task:
1.Write a program in python that will accept 3 inputs from a user. Display the total of those 3 numbers and also display the average.2.Write a program in python that will accept 1 input from the user. Plug that number in the formula 9(8/2+X/2) for X and display the solved an …
View Answer
Content Removal Request
If you are the original writer of this content and no longer wish to have your work published on Myassignmenthelp.com then please raise the
content removal request.
Choose Our Best Expert to Help You
Still in Two Minds? The Proof is in Numbers!
33845 Genuine Reviews With a Rating of 4.9/5.
Business Law
Assignment: 8 Pages, Deadline:
9 days
it was great assignment according to what was important, without mistakes, great
User ID: 8***11 Lincoln, Great Britain
Business Law
Assignment: 6.4 Pages, Deadline:
10 days
The assignment done by professional way and I got more than 85 marks for this subject. Thanks for the whole Nerddz team.
User ID: 2***65 Deepdene, Australia
Psychology
Assignment: 6.8 Pages, Deadline:
10 days
Great work done by the Team Nerddz. I got marks more than 85 for the subject. Thank you…
User ID: 2***65 Deepdene, Australia
Management
Assignment: 6 Pages, Deadline:
4 days
It was nice work and written in a good way. It helped me to increase my final grades for the same course and instructor praised me. Got good grades ov …
User ID: 5***29 Calgary, Canada
Economics
Assignment: 3.5 Pages, Deadline:
2 days
It was nice work and written in a good way. It helped me to increase my final grades for the same course and instructor praised me. 1 star less for im …
User ID: 5***29 Calgary, Canada
Management
Home Work: 3 Pages, Deadline:
1 day
This instructor was really very strict but still gave good marks. Abcdefghijklmno
User ID: 5***29 Calgary, Canada
Management
Thesis: 3 Pages, Deadline:
1 day
Amazing work on this! Got good marks excellent work by the writer. I did not expect so much marks
User ID: 5***29 Calgary, Canada
English
Essay: 1.6 Pages, Deadline:
10 hours
Awesome service. I live it and I will continue to work with them I recommend it. Please do consider
User ID: 8***35 United States
Psychology
Assignment: 6.8 Pages, Deadline:
7 hours
i really appriciate your work. thank you so much. you do your best. and you are very hard worker. thank you so much again again.
User ID: 8***33 Australia
Mechanical Engineering
Home Work: 1 Page, Deadline:
23 hours
The assignment is good and i have submitted it. and i got good marks. I appreciate your good work.
User ID: 7***11 Canada
Business Law
Assignment: 8 Pages, Deadline:
9 days
it was great assignment according to what was important, without mistakes, great
User ID: 8***11 Lincoln, Great Britain
Business Law
Assignment: 6.4 Pages, Deadline:
10 days
The assignment done by professional way and I got more than 85 marks for this subject. Thanks for the whole Nerddz team.
User ID: 2***65 Deepdene, Australia
Psychology
Assignment: 6.8 Pages, Deadline:
10 days
Great work done by the Team Nerddz. I got marks more than 85 for the subject. Thank you…
User ID: 2***65 Deepdene, Australia
Management
Assignment: 6 Pages, Deadline:
4 days
It was nice work and written in a good way. It helped me to increase my final grades for the same course and instructor praised me. Got good grades ov …
User ID: 5***29 Calgary, Canada
Economics
Assignment: 3.5 Pages, Deadline:
2 days
It was nice work and written in a good way. It helped me to increase my final grades for the same course and instructor praised me. 1 star less for im …
User ID: 5***29 Calgary, Canada
Management
Home Work: 3 Pages, Deadline:
1 day
This instructor was really very strict but still gave good marks. Abcdefghijklmno
User ID: 5***29 Calgary, Canada
Management
Thesis: 3 Pages, Deadline:
1 day
Amazing work on this! Got good marks excellent work by the writer. I did not expect so much marks
User ID: 5***29 Calgary, Canada
English
Essay: 1.6 Pages, Deadline:
10 hours
Awesome service. I live it and I will continue to work with them I recommend it. Please do consider
User ID: 8***35 United States
Psychology
Assignment: 6.8 Pages, Deadline:
7 hours
i really appriciate your work. thank you so much. you do your best. and you are very hard worker. thank you so much again again.
User ID: 8***33 Australia
Mechanical Engineering
Home Work: 1 Page, Deadline:
23 hours
The assignment is good and i have submitted it. and i got good marks. I appreciate your good work.
User ID: 7***11 Canada