write a multi-threaded program that generates random passwords

COP-4338 System ProgrammingProgramming Assignment 4:
Multithreading and Synchronization
FIU Knight Foundation School of Comp. & Info Sciences
In this assignment, you will write a multi-threaded program that generates random passwords that are in the form of a sequence of meaningful words in English separated by white
space.
1
Program Command Line Arguments
The program must support the following command-line arguments:
• -p n: specifies the number (n) of producer threads.
• -c m: specifies the number (m) of consumer threads.
• -f file: specifies the name of dictionary file (dict.txt)
• -n k: specifies the number of passwords that program must generate. Assume that k
is always divisible by m.
• -l l: specifies the number of words per password.
2
Input/Output of Your Program
The program gets no input from stdin. It only prints out the generated passwords on the
screen, one password per line.
3
Flow of Program
Your program must first read the dict.txt and store it in an array (words).
Then, it should spawn n producer threads responsible for moving the array (words)
content into a global hash table (given on Canvas) accessible by all threads. Please make
sure to distribute the load of moving data to the hash table evenly between all producers.
Also, since the hash table is going to be manipulated by multiple threads at the same
time, there exists a race-condition possibility that may corrupt the data in the hash table.
1
Therefore, it is necessary to use a mutex-lock to synchronize the access to the hash table
and enforce mutual exclusion when adding words to the hash table.
While the producer threads are populating the hash table, the main thread should wait
for them by calling the join function.
After all producers finish the data transfer, then the main thread spawns m consumer
threads, each responsible for generating k/m passwords and printing them out on the screen.
Each password needs to be generated by:
1. removing l random meaningful words from the global hash table. To pick and remove
a random word, you can use words[rand()%N ] where N is the total number of words
in the dictionary and rand() is a function in stdlib.h (do not forget to initialize the
seed of C’s random number generator by calling srand(time(NULL)))
2. concatenating the words after separating them by comma.
4
Submissions
You need to submit a .zip file compressing the followings:
• all .c and .h files
• makefile which organizes the compilation process of your program. Use the word
“passgenerator” to name the executable of your program.
2

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper
Are you stuck with your online class?
Get help from our team of writers!

Order your essay today and save 20% with the discount code RAPID