logo Use CA10RAM to get 10%* Discount.
Order Nowlogo

This assignment will introduce you to synchronization mechanisms in UNIX using POSIX threads.You must write a program to implement a multithreaded version of the Elias-Gamma decoding algorithm

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS


This assignment will introduce you to synchronization mechanisms in UNIX using POSIX threads.

Specifications:  
You must write a program to implement a multithreaded version of the Elias-Gamma decoding algorithm 

Your program should read its input from stdin (C++ cin) and use input redirection. The user will execute this program using I/O redirection:

./exec_filename < input_filename

where exec_filename is the name of your executable file, and input_filename is the name of the file with the integer values to encode. The format of the input file:

eliasgammacode1 pos1
eliasgammacode2 pos2
                .                  .
eliasgammacoden posn                   

Where eliasgammacode is the encoded representation of the ASCII value (as an integer) of the character in the original file, and pos is the position of this character in the original file. The Elias-Gamma codes in the input file are sorted in ascending order by their ASCII value (using the position in the file in ascending order as the tie-breaker condition if the frequency of a character in the original file is greater than one).

Your program must create a child thread per Elias-Gamma code in the input file.  Each child thread will decode the Elias-Gamma code assigned by the main thread, and print the ASCII representation (character) of the integer value represented by the Elias-Gamma code. You must use the synchronization mechanisms discussed in class to guarantee that the child threads will print the characters in order based on the position of the character in the original file.

Given the following input file:

 0001010 9

 00000100000 4
00000110000 8
00000110011 5
00000110011 6
00000110110 7
0000001000011 0
0000001000011 3
0000001001111 1
0000001010011 2

The expected output is:

COSC 3360
2nd Test:

Input File:

0001010 11
00000100000 6
00000110000 8
00000110000 10
00000110010 7
00000110010 9
0000001000101 4
0000001001101 2
0000001001101 3
0000001010010 5
0000001010011 0
0000001010101 1

CORRECT OUTPUT:

SUMMER 2020

After sorting the contents of the input file based on the position of the characters in the file, we have:

0000001000011 0     //  integer = 67, ASCII = 'C'
0000001001111 1     //  integer = 79, ASCII = 'O'
0000001010011 2     //  integer = 83, ASCII = 'S' 
0000001000011 3     //  integer = 67, ASCII = 'C'
00000100000 4       //  integer = 32, ASCII = ' '
00000110011 5       //  integer = 51, ASCII = '3'

00000110011 6       //  integer = 51, ASCII = '3'
00000110110 7       //  integer = 54, ASCII = '6'

00000110000 8       //  integer = 48, ASCII = '0'
0001010 9           //  integer = 10, ASCII = 'n'

Notes:

  • You can safely assume that the input files will always be in the proper format.
  • You must use POSIX threads. A penalty of 100% will be applied to submissions using a thread library other than pthread.
  • You cannot use pthread_join or sleep to achieve thread synchronization. A penalty of 100% will be applied to submissions using the previous system calls to synchronize the child threads.
  • The main thread must create the child threads based on the order of the Elias-Gamma codes in the input file (not based on the positions of the characters in original file).

 

Expert's Answer

636 Times Downloaded

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

636 Times Downloaded

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

864 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

684 Answers

Hire Me
expert
Husnain SaeedComputer science

830 Answers

Hire Me
expert
Atharva PatilComputer science

848 Answers

Hire Me