Giter Club home page Giter Club logo

cis450_program1's Introduction

CIS 450
Program 1
Team 1: Michael Ingrody and Chris Sims

/******Bounded Buffer******/
	Files:
		boundedBuffer.c

	Implementation: 
			Created a bounded buffer that wraps according to the buffer size.
			Before producing or consuming, the thread waits for the buffer to be empty
			or full, respectively.  This is done with semaphores.  Then it ensures mutual 
			exclusivity with a semaphore before making the changes. At the end of the program,
			the three thread's total iterations will add up to (4950 * 3).

	Instructions: ./boundedBuffer [number of iterations] [buffer size]

	Sample Output:

	./boundedBuffer 100 100
	the total is 4950
	the total is 4950
	the total is 4950

	./boundedBuffer 100 10
	the total is 3940
	the total is 4740
	the total is 6170

/******Bridge******/
	Files:
		bridge.c

	Implementation: 

			This program uses mutex and conditional variables.  Whenever the count for the number
			of cars on the bridge is modified, it is locked to ensure mutual exclusivity.  The conditional
			variable &safe is used to give cars a programming "green light" to cross the bridge.  The algorithm
			supplied along with this implementation	ensures that no collisions or bridge capacity violations
			will occur between the 50 cars trying to cross the bridge.

	Instructions: ./bridge

	Sample Output:

	./bridge
	Car 3 traveling in direction 0 has arrived at the bridge. CurrDir: 0. #Cars: 0.
	Car 6 traveling in direction 0 has arrived at the bridge. CurrDir: 0. #Cars: 1.
	Car 6 traveling in direction 0 is crossing the bridge. CurrDir: 0. #Cars: 2. 
	Car 6 traveling in direction 0 has exited the bridge. CurrDir: 0. #Cars: 1. 
	Car 2 traveling in direction 0 has arrived at the bridge. CurrDir: 0. #Cars: 1.
	.
	.
	.
	Car 49 traveling in direction 1 is crossing the bridge. CurrDir: 1. #Cars: 2. 
	Car 49 traveling in direction 1 has exited the bridge. CurrDir: 1. #Cars: 1. 
	Car 0 traveling in direction 1 has arrived at the bridge. CurrDir: 1. #Cars: 1.
	Car 32 traveling in direction 1 has exited the bridge. CurrDir: 1. #Cars: 1. 
	Car 0 traveling in direction 1 is crossing the bridge. CurrDir: 1. #Cars: 1. 
	Car 0 traveling in direction 1 has exited the bridge. CurrDir: 1. #Cars: 0. 
	Main(): Waited on 50 threads.  Done.

/******Questions******/
	Files:
		questions.c

	Algorithm Design:
	A student can only as a question when the professor is ready to answer a question.
	The professor can only answer a question after a question has been asked.
	A student can only leave after the professor has given an answer to his/her question.
	A student can arrive at anytime during the process but must wait until the professor is next available to ask a question.

	Professor wakes up from nap
	while (true){
		readyForQuestion.signal()
		Student arrives
		readyForQuestion.wait()
		questionStart.wait()
		Student asks question
		answerStart.signal()
		Student waits for answers (answerDone.wait())
		Professor finishes answer (answerDone.signal())
		Student Leaves
		questionStart.signal()
	}
	questionStart.Signal()
	
	Implementation:
	Create a sempaphore for readyForQuestion: initial 0, professor post when he/she is ready for a question
	Create a semaphore for questionStart: initial 1, student wait once they have arrived.
	Create a semaphore for answerStart: professor wait until questions is asked.
	Create a semaphore for answerDone: professor post when answer is given.

	Instructions: ./questions [number of students]

	Sample Output:
	
	./questions 3
	Student 3 is waiting to ask a question.
	Student 2 is waiting to ask a question.
	Student 1 is waiting to ask a question.
	The professor wants to be asked a question.
	Student 3 is asking a question.
	Student 3 is done asking a question.
	Professor is answering the question.
	The professor is finished with the answer.
	Student 3 received the answer and is leaving.
	The professor wants to be asked a question.
	Student 2 is asking a question.
	Student 2 is done asking a question.
	Professor is answering the question.
	The professor is finished with the answer.
	Student 2 received the answer and is leaving.
	The professor wants to be asked a question.
	Student 1 is asking a question.
	Student 1 is done asking a question.
	Professor is answering the question.
	The professor is finished with the answer.
	Student 1 received the answer and is leaving.
	All student questions have been answered.


	./questions 50
	Student 3 is waiting to ask a question.
	Student 4 is waiting to ask a question.
	Student 5 is waiting to ask a question.
	.
	.
	.
	Student 49 received the answer and is leaving.
	The professor wants to be asked a question.
	Student 50 is asking a question.
	Student 50 is done asking a question.
	Professor is answering the question.
	The professor is finished with the answer.
	Student 50 received the answer and is leaving.
	All student questions have been answered.

cis450_program1's People

Contributors

sesmar avatar

Stargazers

Kiryha avatar

Watchers

 avatar  avatar

Forkers

mmii

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.