Example #1
0
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;
}
Example #2
0
void DatabaseThread::AddRequest(Packet * pkt)
{
	_lock.Acquire();
	_queue.push(pkt);
	_lock.Release();
	s_hEvent.Signal();
}
Example #3
0
void passportClerk(int id) {

	int myLineID = id; 	//set ID
	bool firstTime = true;
	//int firstTime = 1;
	bool ifBribed;
	//int ifBribed;
	//int sizeOfInt = sizeof(int);

	while(true) {
		//Wait fot the next cust to signal
		ifBribed = waitForLine(&passPClerk, id, firstTime);


		//Set up some convenient variables
		Lock *workLock = &passPClerk.clerkLock[myLineID];
		//int workLock = *(passPClerk.clerkLock + (myLineID * sizeOfInt));
		Condition *workCV = &passPClerk.clerkCV[myLineID];
		//int workCV = *(passPClerk.clerkCV + (myLineID * sizeOfInt));

		//Now the clerk has been woken up and has been told the customer ID
		//Check
		int customerSSN = passportClerkCurrentCustomer[myLineID];
		//int customerSSN = *(passportClerkCurrentCustomer + (myLineID * sizeOfInt));

		cout<<"PassportClerk #" << id << " has received SSN " << customerSSN << " from Customer #" << customerSSN << ".\n";
		passportClerkChecked[customerSSN] =
				customersWithCompletedApps[customerSSN] && customersWithCompletedPics[customerSSN];
		//*(passportClerkChecked + (customerSSN * sizeOfInt)) = *(customersWithCompletedApps + (customerSSN * sizeOfInt)) && *(customersWithCompletedPics + (customerSSN * sizeOfInt));
		if(!passportClerkChecked[customerSSN]/* *(passportClerkChecked (customerSSN + sizeOfInt)) == 0 */){
			cout<<"PassportClerk #"<<id<<" has determined that Customer #"<<customerSSN<<
					" does not have both their application and picture completed\n";
		}
		else{
			cout<<"PassportClerk #"<<id<<" has determined that Customer #"<<customerSSN<<
			" has both their application and picture completed\n";
		}
		//And Signal
		workCV->Signal(workLock);
		//Signal(workCV, workLock);
		workCV->Wait(workLock);
		//Wait(workCV, workLock);

		//Now customer is gone
		if(passportClerkChecked[customerSSN]/* *(passportClerkChecked + (customerSSN * sizeOfInt)) == 1 */) {
			cout << "PassportClerk #" << id << " has recorded Customer #" << customerSSN <<
			" passport documentation\n";
		}

		if(ifBribed /*ifBribed == 1*/) {
			cout<<"PassportClerk #" << id << " has received $500 from Customer #" << customerSSN << ".\n";
			passPClerk.cashReceived+=500;
		}

		firstTime = false;
		//firstTime = 0;
		workLock->Release();
		//Release(workLock);
	}
}
Example #4
0
BOOL WINAPI _ConsoleHandler(DWORD dwCtrlType)
{
	s_hEvent.BeginSynchronized();
	s_hEvent.Signal();
	s_hEvent.EndSynchronized();
	sleep(10000); // Win7 onwards allows 10 seconds before it'll forcibly terminate
	return TRUE;
}
Example #5
0
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;

}
Example #6
0
void cashierDo(int id) {

	int myLineID = id; 	//set ID
	bool firstTime = true;
	//int firstTime = 1;
	bool ifBribed;
	//int ifBribed;
	//int sizeOfInt = sizeof(int);

	while (true) {
		//Wait fot the next customer to signal
		//cout << "Cashier #" << id << " about to wait for customer\n";
		waitForLine(&cashier, id, firstTime);


		//Set up some convenient variables
		Lock *workLock = &cashier.clerkLock[myLineID];
		//int workLock = *(cashier.clerkLock + (myLineID * sizeOfInt));
		Condition *workCV = &cashier.clerkCV[myLineID];
		//int workCV = *(cashier.clerkCV + (myLineID * sizeOfInt));

		//Now the clerk has been woken up and has been told the customer ID
		//Check
		int customerSSN = cashierCurrentCustomer[myLineID];
		//int customerSSN = *(cashierCurrentCustomer + (myLineID * sizeOfInt));
		
		cout<<"Cashier #" << id << " has received SSN " << customerSSN << " from Customer #" << customerSSN << ".\n";
		cashierChecked[customerSSN] = passportClerkChecked[customerSSN];
		//*(cashierChecked + (customerSSN * sizeOfInt)) = *(passportClerkChecked + (customerSSN * sizeOfInt));
		//And Signal
		workCV->Signal(workLock);
		//Signal(workCV, workLock);
		workCV->Wait(workLock);
		//Wait(workCV, workLock);

		if (!cashierChecked[customerSSN]/* *(cashierChecked + (customerSSN * sizeOfInt)) == 0 */) {
			//Now customer is gone
			cout<<"Cashier #"<<id<<" has recieved $100 from Customer #"<<customerSSN<<
					" before certification. They are to go to the back of the line\n";
			workLock->Release();
			//Release(workLock);
			return;
		}

		//Now customer has paid, so give passport and mark
		cout<<"Cashier #"<<id<<" has verified that Customer #"<<customerSSN<<" has been certified by a PassportClerk\n";
		cout<<"Cashier #"<<id<<" has recieved $100 from Customer #"<<customerSSN<<" after certification\n";
		cout << "Cashier #" << id << " provided Customer #" << customerSSN << " with their completed passport\n";
		cashier.cashReceived+=100;
		gottenPassport[customerSSN] = true;
		//*(gottenPassport + (customerSSN * sizeOfInt)) = 1;
		workCV->Signal(workLock);
		//Signal(workCV, workLock);
		workCV->Wait(workLock);
		//Wait(workCV, workLock);

		//Now customer has left
		cout << "Cashier #" << id << " has recorded that Customer #" << customerSSN <<
				" has been given their completed passport\n";
		firstTime = false;
		//firstTime = 0;
		workLock->Release();
		//Release(workLock);
	}

	//Exit(0);

}