sesmar / cis450_program1 Goto Github PK
View Code? Open in Web Editor NEWRepository for Program 1 from CIS 450
Repository for Program 1 from CIS 450
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.