Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS 370 Spring 2009 - Multithreaded C Sorting Visualization with Termcap - Prof. Andrew R. , Assignments of Operating Systems

An assignment for a cs 370 course in spring 2009 where students are required to write a multithreaded c program using the pthread library and termcap for low-level terminal control. The goal is to gain experience in writing multithreaded applications and working with character devices. Students will implement a bounded buffer for thread communication, create a mapping from string to sort thread entry functions, develop a screen library using termcap, and use the library in the racer.c file. They will also create a snapshot library for progress messages and start threads for each sorting algorithm.

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-p4t
koofers-user-p4t 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 370 Spring 2009
Honors Contract: Racing Sorts
Dr. Andrew R. Dalton
March 23rd, 2009
1 Introduction
For this assignment, you will implement a multithreaded C program that visualizes the differences in running
times among a set of sorting algorithms. You will use the pthread library for multithreading and the termcap
library for low-level terminal control.
POSIX threads (pthreads) is a POSIX standard for threads. The standard defines an API for creating and
manipulating threads. Pthreads are most commonly used on Unix-like POSIX systems such as Linux and
Solaris, but Microsoft Windows implementations also exist.
Termcap is an old, low-level facility that abstracts the description and use of computer terminal devices. In
the past, terminals were more than windows on the screen, they were physical hardware devices. Operating
systems controlled these terminals by sending special text control codes. Each terminal type had (potentially)
different control codes for various operations. Termcap defines a set of attributes, including booleans (does
the terminal have this property or function?), numbers (how many rows and how many columns?), and strings
(what byte sequence do you send to make the terminal do ...?). The facility includes a terminal description
“database” and a collection of functions to get and use the information. Read the curs termcap(3x) and
termcap(5) manual pages for more information.
2 Overview
The purpose of this assignment is two-fold: to give you experience writing multithreaded applications and to
give you experience working with low-level character devices. You will develop a C program that consists of
multiple modules (read “source files”). Each module encapsulates a specific “concern” of the application. I
have provided you with 12 files: a Makefile, 3 header files, and 8 C source files. Embedded within these files
are comments marked with the string TODO. You are to fill in the implementation details for each of these
comments. These implementation details will include (not necessarily in this order):
1. The introduction of a bounded (i.e., “fixed size”) buffer that is shared among the threads in your
program. This buffer will be used to enable sorting threads to communicate with the main thread. This
bounded buffer should be implemented as an abstract data type, with all mutex locking and unlocking
code implemented within the ADT. You may use any of the examples we’ve discussed in class for this
portion of the assignment.
2. The creation of a mapping from string to sort thread entry function. This mapping will be used to
“lookup” sorting algorithms by their name.
3. The development of a simple “screen” library using termcap. You will make calls to functions in the
termcap library to lookup information about your terminal type and provide functions for accessing and
using that information. This will be contained within screen.c.
The screen library will use the ioctl() system call to retrieve and set parameters associated with the
character device associated with the terminal. See man 2 ioctl for information about the ioctl() system
call and man tty ioctl about specifics related to getting and setting terminal attributes. You will be
interested in TCGETA and TCSETA.
1
pf2

Partial preview of the text

Download CS 370 Spring 2009 - Multithreaded C Sorting Visualization with Termcap - Prof. Andrew R. and more Assignments Operating Systems in PDF only on Docsity!

CS 370 Spring 2009

Honors Contract: Racing Sorts

Dr. Andrew R. Dalton

March 23rd, 2009

1 Introduction

For this assignment, you will implement a multithreaded C program that visualizes the differences in running times among a set of sorting algorithms. You will use the pthread library for multithreading and the termcap library for low-level terminal control.

POSIX threads (pthreads) is a POSIX standard for threads. The standard defines an API for creating and manipulating threads. Pthreads are most commonly used on Unix-like POSIX systems such as Linux and Solaris, but Microsoft Windows implementations also exist.

Termcap is an old, low-level facility that abstracts the description and use of computer terminal devices. In the past, terminals were more than windows on the screen, they were physical hardware devices. Operating systems controlled these terminals by sending special text control codes. Each terminal type had (potentially) different control codes for various operations. Termcap defines a set of attributes, including booleans (does the terminal have this property or function?), numbers (how many rows and how many columns?), and strings (what byte sequence do you send to make the terminal do ...?). The facility includes a terminal description “database” and a collection of functions to get and use the information. Read the curs termcap(3x) and termcap(5) manual pages for more information.

2 Overview

The purpose of this assignment is two-fold: to give you experience writing multithreaded applications and to give you experience working with low-level character devices. You will develop a C program that consists of multiple modules (read “source files”). Each module encapsulates a specific “concern” of the application. I have provided you with 12 files: a Makefile, 3 header files, and 8 C source files. Embedded within these files are comments marked with the string TODO. You are to fill in the implementation details for each of these comments. These implementation details will include (not necessarily in this order):

  1. The introduction of a bounded (i.e., “fixed size”) buffer that is shared among the threads in your program. This buffer will be used to enable sorting threads to communicate with the main thread. This bounded buffer should be implemented as an abstract data type, with all mutex locking and unlocking code implemented within the ADT. You may use any of the examples we’ve discussed in class for this portion of the assignment.
  2. The creation of a mapping from string to sort thread entry function. This mapping will be used to “lookup” sorting algorithms by their name.
  3. The development of a simple “screen” library using termcap. You will make calls to functions in the termcap library to lookup information about your terminal type and provide functions for accessing and using that information. This will be contained within screen.c.

The screen library will use the ioctl() system call to retrieve and set parameters associated with the character device associated with the terminal. See man 2 ioctl for information about the ioctl() system call and man tty ioctl about specifics related to getting and setting terminal attributes. You will be interested in TCGETA and TCSETA.

CS 370 Spring 2009

You will use the function tcsetattr() (man termios) to set parameters associated with the terminal. Specifically, you’ll want to adjust the output mode of the terminal (c oflag) to enable implementation- defined output processing.

  1. The use of your screen library in racer.c. The ultimate goal is to use the functions provided by the screen library to dynamically updated the “racing sorts” on screen.
  2. The development of a “snapshot” library that ties into the bounded buffer to deliver “progress messages” from sorting threads to the main thread.
  3. The introduction of code to start a set of threads associated with each of the sorting algorithms specified on the command line.

Please note: I have left many portions of this assignment abstract – this was intentional. I expect that you may have to spend some time reading the associated manual pages before you’ll be able to complete the assignment. (This is especially true with respect to the termcap portion of the assignment.) My suggestion is to start with the threading code and instead of using the terminfo code, just have your program print progress as separate lines to the screen. Once that’s working, then move on to the terminfo code. Please do not hesitate to ask me questions; I can, if nothing else, point you in the right direction.

After completing the implementation, you are required to schedule a time to meet with me to discuss your implementation. Be prepared to discuss the rational behind the different design choices you make.

Most important — have fun!