OPERATING SYSTEMS Programming Assignment # 3

$24.99 $18.99

In this assignment, you will write a program that uses threads and synchronization to read from a file, modify its contents and write to the same file. You will implement a program with four types of threads, structured like: After there is at least one entry in the array, the Upper Threads will read the…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

In this assignment, you will write a program that uses threads and synchronization to read from a file, modify its contents and write to the same file. You will implement a program with four types of threads, structured like:

After there is at least one entry in the array, the Upper Threads will read the array indices one by one and change the content to uppercase. Note that all Upper Threads have to read a different array index. Note also that Upper Threads should work concurrently with Replace Threads.

After there is at least one entry in the array, the Replace Threads will read the array indices one by one and substitute all of the spaces with underscore characters. Note that all Replace Threads have to read a different array index. Note also that Replace Threads should work concurrently with Upper Threads, which means that a line can be modified first by a Replace Thread and then an Upper Thread or first by an Upper Thread and then a Replace Thread. However, no multiple modifications can be done at the same time. You have to make sure if one of Upper or Replace Threads is working on an index, the other one should not be able to.

After both of the modifications are done with at least one array index, the Writer Threads will update the file’s appropriate line with the array’s corresponding entry. Note that there could be only one Writer Thread that can write to the file. Note also that you have to make sure no same writer thread updates the same line of the file.

The main thread is responsible for creating all of the threads and waiting for them. Note that, all of the threads has to exist in the system at the same time, and you have to work on synchronizing them.

All the threads have to print information about their job on the screen (see the example execution below).

Note that there is global queue requested and the queue can be accessed by many threads of different types so a synchronization is necessary for the queue. This can be achieved by using the semophores.

The global queue has to be created at the very first time a thread needs to use it by that thread. Preserving consistency and preventing deadlocks are major issues to be considered.

When a thread is done with its job, it has to check if there are more jobs to do. (e.g.: When a Replace Thread is done with one line, it has to check the array once more to see if there are more indices that are not modified by a Replace Thread yet.)

Multiple simultaneous operations on different parts of the queue should be allowed in your solution.

Your program will be executed as follows:

    • Example:

./project3.out -d deneme.txt -n 15 5 8 6

    • The -d option represents the name of the file you will read from(a simple text file), -n option represents the numbers of threads to be created of each type (Read, Upper, Replace, Write, respectively).

Your program should produce output.

    • Example:

<Thread-type and ID>

<Output>

Read_1

Read_1 read the line 1 which is “This is an example line.”

Read_2

Read_2 read the line 2 which is “This is another line.”

Upper_2

Upper_2 read index 2 and converted “This is another line.” to

THIS IS ANOTHER LINE.”

Replace_2

Replace_2 read index 1 and converted “This is an example line.” to

This_is_an_example_line.”

Upper_1

Upper_1 read index 1 and converted “This_is_an_example_line.” to

THIS_IS_AN_EXAMPLE_LINE.”

Replace_1

Replace_1 read index 2 and converted “THIS IS ANOTHER LINE.”

to “THIS_IS_ANOTHER_LINE.”

Writer_1

Writer_1 write line 1 back which is

THIS_IS_AN_EXAMPLE_LINE.”

Writer_3

Writer_3 write line 2 back which is “THIS_IS_ANOTHER_LINE.”

….. … ….. ….

Notes:

The project will be done in Linux operating system using C programming language. You must use PThread library and synchronization appropriately in your code.

Take into account materials and examples covered in the lab sessions. Consider all necessary error checking for the programs.

No late homework will be accepted!

In case of any form of copying and cheating on solutions, all parties/groups will get

ZERO grade. You should submit your own work.

You have to work in groups of two.

If after 3 projects, your overall grade is higher than 100, it will be considered as 100.

What to submit?

A softcopy of your source codes which are EXTENSIVELY commented and appropriately structured and a project report (minimum 2-page) that contains the detailed information about your implementation should be emailed to cse333.projects@gmail.com. All the files should be submitted as one zip file. You should use your student numbers as the name of the file: student#1_student#2_project3.zip

4

OPERATING SYSTEMS Programming Assignment # 3
$24.99 $18.99