Code Monkey home page Code Monkey logo

unisex-bathroom's Introduction

Unisex Bathroom Problem

Description

This is a work from the Concurrent Programming course in which two solutions were implemented using different methods of synchronization. The methods used to solve the problem were explicit locks and semaphores.

Problem

Unisex Bathroom

An office has a bathroom that can be used by both men and women, but not both at the same time. If a man is in the bathroom, other men may enter, but any women wishing to use the bathroom should wait for it to be empty. If a woman is in the bathroom, other women may enter, but any men wishing to use the bathroom should wait it to be empty. Each person (man or woman) will spend some time using the bathroom.

Design and implement a concurrent solution to the problem. The program should show when a person (man or woman) enters or exits the bathroom; as well as how many people (men or women) are in the bathroom at the moment. Because it is a space of relatively small size, the bathroom has a limiting capacity of persons C (provided as input via the command line or prefixed as a constant value) that can use it at the same time and the time that each person passes in the bathroom is random and different to each program execution.

Compiling and Running

We usually use an IDE (like NetBeans or Eclipse) to compile and build the program, but if you want to compile via terminal use the following commands.

Dependencies

  • Java 8.0 or greater

Unisex Bathroom Lock

Open the project folder:

cd UnisexBathroomLock

How to compile

Run the following commands:

./make.sh
make.sh content
#!/bin/bash
cd src
# Compile
javac unissexbathroomlock/control/*.java unissexbathroomlock/bathroom/*.java unissexbathroomlock/person/*.java
# Generate jar
jar cfm ../UnisexBathroomLock.jar ../manifest.mf unissexbathroomlock/control/*.class unissexbathroomlock/bathroom/*.class unissexbathroomlock/person/*.class

How to run

java -jar UnisexBathroomLock.jar

Unisex Bathroom Semaphore

Open the project folder:

cd UnisexBathroomSemaphore

How to compile

Run the following commands:

./make.sh
make.sh content
#!/bin/bash
cd src
# Compile
javac unisexbathroomsemaphore/control/*.java unisexbathroomsemaphore/bathroom/*.java unisexbathroomsemaphore/person/*.java
# Generate jar
jar cfm ../UnisexBathroomSemaphore.jar ../manifest.mf unisexbathroomsemaphore/control/*.class unisexbathroomsemaphore/bathroom/*.class unisexbathroomsemaphore/person/*.class

How to run

java -jar UnisexBathroomSemaphore.jar

Team

Breno Viana Patrícia Cruz

unisex-bathroom's People

Contributors

brenomfviana avatar

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.