Question: Task 1(a) Deadlock - 6 marks This task does not have a Fitchfork component. You only have to submit this task as part of your

Task 1(a) Deadlock - 6 marks This task does not have a Fitchfork component. You only have to submit this task as part of your nal submission. In this task, you are required to implement methods in the given le deadlock.cpp downloaded from the CS website. Your need to implement these using threads, you may use high level C++ threads or pthreads for this purpose. Methods to implement are dened below: 1. writeToFile(int threadNumber) - this simply writes data to a le called "dead- lock.txt", the data that must be written consists of the following: - The rst 10 iterations of the product of the thread number and i separated by a single space. - Where i is a loop variable from 1 to 10. - Example: if thread number is 2 the data that should be written to the le is: [ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]. 2. lock() - implement any type of locking mechanism of your choice. You may use a library for this. 3. unlock() - implement a unlocking mechanism with relation to the way you imple- mented the lock() function. 4. main(...) - You should have one command line argument that accepts the number of threads to create. - For each thread created you need to display a message as well as the thread ID. - Your threads should call the threadFunction() function. Things to note: 1. You may NOT modify the function threadFunction() in this task. 2. Every time the program executes the contents of the le should be overwritten. Your output should look something like this: 4

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!