Assignment 3

  • Compile problem 1 with: clang Assignment3Problem1.cpp -o problem1
  • Run problem 1 with: ./problem1
  • Compile problem 2 with: clang Assignment3Problem2.cpp -o problem2
  • Run problem 2 with: ./problem2

Problem 1

By creating a queue to start which contains a randomly shuffled list of every guest's gift. This minimizes the time taken to fetch the current guest's present and add it to the linked list (represented as linked_guests). Then, we use two separate locks, one for the queue and one for the lists to lock others out while they are using data.

Problem 2

I'm cutting the time to 1 second per temperature reading & 10 seconds per report to save time. Each temperature is stored in a vector which is held in an array whose index is tied to the thread it belongs to. This ensures that each thread doesn't touch other's data. When the report is due, it locks all other threads and collects the data to analyze before clearing all of the data in each vector, starting the process over again. This ensures the report & data collection is timely with no hiccups as threads wait for each other to run.