Example #1
0
void *Student(void *arg)
{
	long id = (long) arg;

	pthread_mutex_lock(&office_mutex);
	// Student may enter the office if there is occupancy.
	if (studentsInside < officeLimit) {
		StudentEntersOffice(id);
	} else {	// Students must wait for space if there is no occupancy.
		while (!officeCondition)
			pthread_cond_wait(&office_capacity_cv, &office_mutex);
		officeCondition = 0;

		StudentEntersOffice(id);
	}
	pthread_mutex_unlock(&office_mutex);

	int questionNumber = id % 4 + 1;

	while (questionNumber > 0) {
		pthread_mutex_lock(&student_mutex);
		StartQuestion(id);

		// Signal the professor that a student has posed a question
		studentCondition = 1;
		pthread_cond_signal(&student_question_cv);

		pthread_mutex_lock(&student_question_mutex);

		// Wait for the professor to finish answering the question.
		while (!professorCondition)
			pthread_cond_wait(&professor_complete_cv, &student_question_mutex);
		professorCondition = 0;

		QuestionComplete(id);
		pthread_mutex_unlock(&student_question_mutex);

		pthread_mutex_unlock(&student_mutex);
		questionNumber--;
		sleep(1);	// Students must wait before posing an additional question.
	}
	StudentLeavesOffice(id);
}
Example #2
0
void CMainDialog::StartQuestion(ResTextType text, bool warningYes, bool warningNo, bool fireParticles, DialogCallback yes, DialogCallback no)
{
    std::string name;
    GetResource(RES_TEXT, text, name);
    StartQuestion(name, warningYes, warningNo, fireParticles, yes, no);
}