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.
This file contains the all C++ source code, including the following contents:
Rowstruct: stores information about the work to be done by the threads. A row's attributes are id, name, and count.ThreadInfostruct: stores information necessary for the threads to be able to do their work. Attributes include id, index, whether it has been released, and more.StartRoutinefunction: 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.
Header file for main.cc. Optional in the project requirements; in this solution, this file is not used.
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 bymain(); each thread then releases the next thread
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.
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