Skip to content

Latest commit

 

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSCE 311 Project 1 -- Scheduling Threads

This project implements threading using POSIX threads in a Linux environment with C++. It reads a user-specified text file that includes strings to be encrypted through a hashing function and the number of times each string should be hashed, printing results. The project's requirements avoid addressing concurrency issues, instead accepting race conditions and observing their effects.

File contents:

main.cc

This file contains the all C++ source code, including the following contents:

  • Row struct: stores information about the work to be done by the threads. A row's attributes are id, name, and count.
  • ThreadInfo struct: stores information necessary for the threads to be able to do their work. Attributes include id, index, whether it has been released, and more.
  • StartRoutine function: function returning a void pointer which is passed as an argument in pthread_create(). Handles thread sleeping, row/work completion, timeout checking, and in some cases releasing subsequent threads.
  • main() function: Reads in the rows from the text file and gathers the number of processors on the user's computer. Creates that many threads and prompts the user for how many they would like to use, releasing them and waiting until they have all completed their work before printing the results and returning.

main.h

Header file for main.cc. Optional in the project requirements; in this solution, this file is not used.

Additional design information:

Release modes

This program allows for three different strategies for thread release:

  • --all: all threads are released immediately
  • --rate: threads are released one at a time, 1ms apart
  • --thread: only the first thread is released by main(); each thread then releases the next thread

Timeouts

Each thread is allowed to work for a certain amount of time. If the thread has not finished its work within this time constraint, it times out and does not complete its remaining tasks. The timeout length can be specified by the user, or left out for a default timeout of 3000 ms.

Running the program

This folder contains a makefile to build the program files. It also requires 1-2 flags to be called and the input of a text file. After building, make a call of this format from the project's root directory:

./bin/proj1 [release mode flag] [optional timeout flag] < [text file]

Example command line call for this program:

make
./bin/proj1 --all --timeout 5000 < dat/medium.txt

About

project 1 for csce311

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages