#include #include #include #include #include #include "dining.h" using namespace std; int main (int argc, char **argv) { srand (time (nullptr)); cout << "How many philosophers? "; string numstr; getline (cin,numstr); num = atoi(numstr.c_str()); locks = new pthread_mutex_t [num]; th = new pthread_t[num]; id = new int[num]; for (int i=0; i < num; i++) id[i] = i; for (int i=0; i < num; i++) pthread_create (&th[i],nullptr,phil,&id[i]); for (int i=0; i < num; i++) pthread_join (th[i],nullptr); delete[] th; delete[] id; delete[] locks; return 0; } void * phil (void *a) { while (true) { int idnum = *(int*)a; int pause = 1+rand()%10; cout << to_string(idnum)+": Thinking\n";cout.flush(); // sleep (pause); pause = 1+rand()%10; /* If my id is idnum, the fork to my left is idnum and the fork to my right is idnum+1 (after wrapping back to zero if necessary) */ cout <