CSCI 360: Introduction to Operating System 1 | P a g e Assignment 4: Sleeping Teaching AssistantObjectives 1. Learn how to synchronize threads using semaphore. 2. Learn how to avoid...

1 answer below »
Programming in c++


CSCI 360: Introduction to Operating System 1 | P a g e Assignment 4: Sleeping Teaching Assistant Objectives 1. Learn how to synchronize threads using semaphore. 2. Learn how to avoid race conditions using mutex-lock. 3. Learn how to avoid deadlock while using mutex-lock and semaphore. 4. Learn pthread_create(), pthread_join(), pthread_cancel(), pthread_mutex_init(), pthread_mutex_destroy(), pthread_mutex_lock(), and pthread_mutex_unlock() function calls from pthread thread library. 5. Learn sem_init(), sem_destroy(), sem_wait(), and sem_post() system calls from semaphore library. 6. Implement Sleeping TA Simulator using above function calls in C programming language. Specifications Assume Vancouver Island University (VIU) Computer Science (CS) department has a Teaching Assistant (TA) who helps undergraduate students with their programming assignments during regular office hours. The TA’s office is rather small and has room for only one desk with a chair and computer. There are fixed number of chairs in the hallway outside TA office where students can sit and wait if the TA is currently helping another student. When there are no student to seek help, the TA sits at the desk and takes a nap. If a student arrives during office hours and finds the TA is sleeping, the student must awaken the TA and ask for help. If a student arrives and finds the TA currently helping another student, the student sits on one of the chairs in the hallway and waits. If no chair is available to sit, the student will come back at a later time. Using POSIX threads, mutex locks, and semaphores, implement a solution that coordinates the activities of the TA and the students. Using pthreads, begin by creating n students. Each will run as a separate thread. The TA will run as a separate thread as well. Student threads will alternate between programming for a period of time and seeking help from the TA. If the TA is available, they will obtain help. Otherwise, they will either sit in a chair in the hallway or, if no chair is available, will resume programming and will seek help at a later time. If a student arrives and notices that the TA is sleeping, the student must notify the TA using a semaphore. When the TA finishes helping a student, the TA must check (notify the students using a semaphore) to see if there are students waiting for help in the hallway. If so, the TA must help each of these students in turn. If no students are present, the TA may return to napping. Simulate students programming—as well as the TA providing help to a student—using the appropriate threads sleep for a random period of time. You can use sleep() system call in this regard. CSCI 360: Introduction to Operating System 2 | P a g e Tasks 1. You will submit this assignment using GIT submission system. A central repository named ‘assignment4” has been created for this assignment. 2. Create your own fork of assignment4 on the central GIT repository using following command: ssh csci fork csci360/assignment4 csci360/$USER/assignment4 3. Go into your csci360 folder that you have created in assignment1 and create a clone of your forked assignment4 repository using following command: git clone csci:csci360/$USER/assignment4 4. Repository assignment4 has been organized as follows: assignment4 bin build include resource src Makefile README example bin A README file template has been placed in the root of the application development folder. The README file gives a general idea of the application, technologies used in developing the application, how to build and install the application, how to use the application, list of contributors to the application, and what type of license is given to the users of the application. You will need to complete the README file before your final submission. The specifications or header files (config.h, logger.h, student.h, ta.h, queue.h, and simulator.h) have been placed in include sub folder. CSCI 360: Introduction to Operating System 3 | P a g e All source codes (logger.c, student.c, ta.c, queue.c, and simulator.c) go into src sub folder. You will implement functions specified in the header files logger.h, student.h, ta.h, queue.h, and simulator.h in the source code files logger.c, student.c, ta.c, queue.c, and simulator.c respectively. All object files will be placed in build sub folder and executable files in bin sub folder by make. Data files are placed in resource folder. There is no data file in this assignment. A Makefile has been placed in the root of the application development folder. The Makefile does the followings and you don’t need to and must not modify Makefile: a) Defines and uses macros for each GCC flag that you are going to use to compile the codes and objects. b) Defines and uses macros for each sub folder of the application, e.g., src, include, resource, build, and bin. c) Uses GCC debug flag to facilitate debugging using gdb. d) Uses GCC include flag to specify the path of application’s custom header files so that the code does not need to specify relative path of these header files in #include pre-processor macro. e) Creates individual object file (*.o) into build folder from each source (*.c) file of src folder. f) Links the necessary object files from the build folder into a single executable file in bin folder. g) Runs the main executable of the application from bin folder. h) Cleans or removes files from both build and bin folders using PHONY target named clean. 5. One example executable (simulator) of this application has been placed in the example/bin folder. You can run this executable to get an idea what is expected from you in this assignment. To run the example executable type the following: make run-example This example executable has been built and tested in Linux Debian machines available in the labs. Run this executable in other kind of machines at your own risks. Make clean command will not delete this example executable and you should not delete it either. 6. Type following at the command prompt to clean previously built artefacts (binary and object files) of the application: make clean 7. Type following at the command prompt to build the application from your own source code: make 8. Type following at the command prompt to run your own application: make run CSCI 360: Introduction to Operating System 4 | P a g e 9. Make sure you can compile, link, run, and test this application error and warning free. 10. Complete the README file. Therefore, you need to give the general description of the application, technologies that are used in the application, how a user can build (compile and link) and install the application, how a user can run the application after the installation. Mention instructor’s name and your name in the list of contributors. Give GPL license to the users to use the application. You can google to find README examples if you are not sure how to write one. 11. Organize and comment your code to make it easy to understand. Make sure you have typed your name and student number in the top comment section in each .c file. Make sure you have deleted all debugging print codes that you were using to debug your code during your development time but not necessary in the final code. Also, make sure you have deleted all commented out codes from your final submission. 12. Continue your work in your cloned or local assignment4 repository and commit and push your work to your central assignment4 repository as it progresses. Deadline and Submission The deadline to demonstrate this assignment in the lab is November 24, 2022 and the deadline to submit the code of this assignment is 11:00 PM on November 24, 2022. This assignment will be evaluated to zero without lab demonstration and code submission. Commit and push your work from your local repository to your remote repository regularly. Use following git commands to commit and push your work from your local repository to your remote repository from your project’s root folder: git add --all git commit –am”Commit message” git push origin master Remember ‘git add --all’ has double dashes before ‘all’. You can also use ‘git add .’ dot option instead of ‘all’ option. Both options do the same, add all the new and the modified files into the commit index. If you want to add only a specific file into the commit index, you can specify the relative path of the file instead of dot or ‘all’ option. For example, if you want to add only prog.cpp file of the src folder into the commit index, you can use ‘git add src/prog.cpp’ command. You can also include multiple files or paths separated by space in the same ‘git add’ command instead of using multiple ‘git add’ commands. Command ‘git add’ is necessary before each ‘git commit’ command. If you skip ‘git add’ command before a ‘git commit’ command, it does not perform the CSCI 360: Introduction to Operating System 5 | P a g e actual commit of the new and modified files into the repository. Always type a meaningful message in your ‘git commit’ command’s ‘-m’ option. For example, if you are committing after adding all the necessary comments into your ‘Makefile’, use ‘git commit –m“Added Makefile comments”’. Remember there is a single dash before m in ‘git commit’ command. It is not recommended to make a huge commit instead of a number of small commits. It is also recommended to avoid unnecessary commits. Commits should reflect the check points of your software development milestones. Command ‘git push’ is necessary to push the local commit to the remote repository. If you skip ‘git push’ after a ‘git commit’, your local and remote repository will become unsynchronized. You must keep your local and remote repositories synchronized with each other using ‘git push’ after each ‘git commit’.
Answered 16 days AfterNov 06, 2022

Answer To: CSCI 360: Introduction to Operating System 1 | P a g e Assignment 4: Sleeping Teaching...

Pratyush answered on Nov 21 2022
40 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here