CSC-4730 / P6 / MutexSpit.hpp
MutexSpit.hpp
Raw
// CSC_4730 | P6 | Header | Caleb Collar & Kai Kuebler | 10.29.21
#pragma once
#include <algorithm>
#include <cstdint>
#include <getopt.h>
#include <iomanip>
#include <iostream>
#include <mutex>
#include <random>
#include <stdlib.h>
#include <thread>
#include <time.h>
#include <vector>
#include <fstream>
#include <string>

using namespace std;

template <typename T> 
class Spit {
public:
  // Public methods.
  void PlayGame();
  Spit(uint64_t sz, uint64_t seed, uint32_t numPlayers); // constructor, InitializeNumbers()
  Spit(vector<T> &deck, uint32_t numPlayers);
  ~Spit(); // joins the threads.

private:
  // Private data members.
  vector<T> deck;         // The deck to be divided among players.
  vector<thread> players; // The players (threads) in the game.
  volatile T pile = 0;    // The critical section.
  mutex m;                //
  uint64_t size;    // Size and seed for the random number generator.
  uint32_t numPlayers;    // Number of threads to use.

  // Private methods.
  void action(vector<T> subDeck, uint32_t tid);
};