void doCashierStuff(int mySSN, int* cash){ int socialSecurityNum = mySSN; //int sizeOfInt = sizeof(int); //First get in line with a generic method //cout<<"Customer #"<<socialSecurityNum<<" getting in cashier line\n"; int myLine = getInLine(&cashier,socialSecurityNum,cash); //Enter interaction monitor with passport clerk Lock* workLock = &cashier.clerkLock[myLine]; //int workLock = *(cashier.clerkLock + (myLine * sizeOfInt)); Condition* workCV = &cashier.clerkCV[myLine]; //int workCV = *(cashier.clerkCV + (myLine * sizeOfInt)); workLock->Acquire(); //Acquire(workLock); //Tell Clerk CV, then wait cout<<"Customer #"<<socialSecurityNum<<" has given SSN "<<socialSecurityNum<<" to Cashier #"<<myLine<<"\n"; tellCashierSSN(mySSN,myLine); workCV->Signal(workLock); //Signal(workCV, workLock); workCV->Wait(workLock); //Wait(workCV, workLock); //Decide weather to self-punish bool readyToPay = cashierChecked[mySSN]; //int readyToPay = *(cashierChecked + (mySSN * sizeOfInt)); if(!readyToPay/*readyToPay == 0*/) { //Release, punish, and leave cout<<"Customer #"<<socialSecurityNum<<" has gone to Cashier #"<<myLine<<" too soon. "<< "They are going to the back of the line.\n"; workCV->Signal(workLock); //Signal(workCV, workLock); workLock->Release(); //Release(workLock); punish(punishTime); return; } //Now you can pay cout<<"Customer #"<<socialSecurityNum<<" has given Cashier #"<<myLine<<" $100\n"; payCashier(mySSN,cash); workCV->Signal(workLock); //Signal(workCV, workLock); workCV->Wait(workLock); //Wait(workCV, workLock); //Now you've been woken up because you have the passport, so leave //cout<<"Customer #"<<socialSecurityNum<<" got passport and is leaving cashier #"<<myLine<<"\n"; workCV->Signal(workLock); //Signal(workCV, workLock); workLock->Release(); //Release(workLock); return; }
void doPassportClerkStuff(int socialSecurityNum,int*cash){ int mySSN = socialSecurityNum; //int sizeOfInt = sizeof(int); //First get in line with a generic method //cout<<"Customer #"<<socialSecurityNum<<" getting in passport Line\n"; int myLine = getInLine(&passPClerk,socialSecurityNum,cash); //Enter interaction monitor with passport clerk Lock* workLock = &passPClerk.clerkLock[myLine]; //int workLock = *(passPClerk.clerkLock + (myLine * sizeOfInt)); Condition* workCV = &passPClerk.clerkCV[myLine]; //int workCV = *(passPClerk.clerkCV + (myLine * sizeOfInt)); workLock->Acquire(); //Acquire(workLock); //Tell Clerk CV, then wait cout<<"Customer #"<<socialSecurityNum<<" has given SSN "<<socialSecurityNum<<" to PassportClerk #"<<myLine<<"\n"; tellPassportClerkSSN(mySSN,myLine); workCV->Signal(workLock); //Signal(workCV, workLock); workCV->Wait(workLock); //Wait(workCV, workLock); //Now leave //cout<<"Customer #"<<socialSecurityNum<<" leaving passportClerk #"<<myLine<<"\n"; workCV->Signal(workLock); //Signal(workCV, workLock); workLock->Release(); //Release(workLock); //Decide weather to self-punish bool myPassportChecked = passportClerkChecked[mySSN]; //int myPassportChecked = *(passportClerkChecked + (mySSN * sizeOfInt)); if(!myPassportChecked /*myPassportChecked == 0 */) { cout<<"Customer #"<<socialSecurityNum<<" has gone to PassportClerk #"<<myLine<<" too soon. "<< "They are going to the back of the line.\n"; punish(punishTime); } return; }
static void prefork() { sLock.Acquire(); }