0% found this document useful (0 votes)
45 views2 pages

Assignment 3

The document provides instructions for an assignment on threading and locks for an operating systems class. It contains 4 questions: 1) Create 9 threads to calculate the values of a 3x3 resultant matrix from multiplying two 3x3 input matrices. 2) Read lines from an input file into threads, capitalize the lines, and write to output files - first without locks, then using mutex locks, then using semaphores. 3) Use threads and semaphores to read the 12 lines of an input file with only 3 threads reading at a time. 4) Generate and print numbers 1-100 using 100 threads but have threads with numbers divisible by 5 print at the end.

Uploaded by

hassan499
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views2 pages

Assignment 3

The document provides instructions for an assignment on threading and locks for an operating systems class. It contains 4 questions: 1) Create 9 threads to calculate the values of a 3x3 resultant matrix from multiplying two 3x3 input matrices. 2) Read lines from an input file into threads, capitalize the lines, and write to output files - first without locks, then using mutex locks, then using semaphores. 3) Use threads and semaphores to read the 12 lines of an input file with only 3 threads reading at a time. 4) Generate and print numbers 1-100 using 100 threads but have threads with numbers divisible by 5 print at the end.

Uploaded by

hassan499
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES

ISLAMABAD
OPERATING SYSTEMS SPRING 2019

ASSIGNMENT 03
Instructions:

• Zero marks will be awarded to the students involved in plagiarism.


• All the submissions will be done on slate.
• Create separate file for each question.
• Be prepared for viva or anything else after the submission of
assignment for two weeks.

Threading and Locks

Question 1: Submit .cpp file.

Multiplication of matrix does take time surely. Time complexity


of matrix multiplication is O (n^3) using normal matrix multiplication.
But, is there any way to improve the performance of matrix
multiplication using normal method. Multi-threading can be done to
improve it. In multi-threading, instead of utilizing a single core of your
processor, we utilizes all or more core to solve the problem. You have to
create different threads, each thread evaluating one element of resultant
matrix.

The value 8 is calculated using only one thread so; you have to
calculate each value of resultant matrix using a thread. Take two matrices
(A and B of size 3x3 both) from user your resultant matrix is of size
3x3 you have to create 9 threads for calculation of each value of
resultant matrix.
Question 2: Submit three .cpp files and three .txt files.
Input.txt file is given with this assignment. You have to
use this input.txt file in this question. You have to read your inpu.txt file
line by line in main thread, create a thread against your each line of file
and pass that line to your created thread. Each thread has to capitalize
the line pass to it and write it on output.txt your writing should be done
char by char. First you have to implement this without using any lock or
join, and then you have to do it using Mutex and generate output.txt, in
last you have to implement it using Binary Semaphore and generate
output.txt.

Question 3: Submit .cpp file.

You have to use input.txt file in this question also. There are total
12 lines in the input.txt. You have to read this file using multiple threads
each line should be read by only one thread. But only three threads are
allowed to read from file at a time. Each thread will output its read line.
You have to use semaphore.

Question 4: Submit .cpp file.

Generate numbers from 1 to 100 using hundred threads each


thread will generate a number and print its number. But each 5th thread
should not generate number and print until all the remaining 80 threads
executed. Which means the numbers which are multiple of 5 will be
printed at the end.

You might also like