Month: September 2014

Want to see more women in tech, Donate to Ada Initiative!

 

Donate now

Ever felt lonely in the male dominated tech society? Ada initiative is the right place for you. Ada initiative is an non profit organization which supports women in open technology and culture. In there, you can find women who will be willing to share your ideas, worries and support you in any way they can.

Ada initiative supports women in tech through workshops on teaching skills, teaching how to handle difficulties in dealing with the tech society like handling imposter syndrome and harassment. It helps to get women involve in open source, open data, open education and other sort of open technology and knowledge fields. It’s a feminist organization which creates sustainable system to support women in tech.

Ada initiative is named for Countless Ada Lovelace, who considered to be the first programmer.

If you feel that you want to do something to increase the number of women in tech world, here is your opportunity. Support Ada Initiative and it’s events. Show that you care.

 
Donate now

Senate Bus Problem

Problem Description

Riders come to a bus stop and wait for a bus. When the bus arrives, all the waiting riders invoke boardBus, but anyone who arrives while the bus is boarding has to wait for the next bus. The capacity of the bus is 50 people; if there are more than 50 people waiting, some will have to wait for the next bus. When all the waiting riders have boarded, the bus can invoke depart. If the bus arrives when there are no riders, it should depart immediately.

Solution

public void busAction() throws InterruptedException {

// acquire the lock so that any riders can't enter the waiting area
mutexWaitingArea.acquire();
if (waitingRiders > 0) {
// if there are riders waiting signal the bus to wait
busWaiting.release();
// wait till all the riders get in to bus
// lock can be acquired only if a rider release it signaling all the
// riders has got in
allAboard.acquire();
}
depart();

// release the lock on waiting area so others can enter
mutexWaitingArea.release();

}

 

public void busAction() throws InterruptedException {

// acquire the lock so that any riders can't enter the waiting area
mutexWaitingArea.acquire();

currentBus = Thread.currentThread();

if (waitingRiders > 0) {
// if there are riders waiting signal the bus to wait
busWaiting.release();
// wait till all the riders get in to bus
// lock can be acquired only if a rider release it signaling all the
// riders has got in
allAboard.acquire();
}
depart();

// release the lock on waiting area so others can enter
mutexWaitingArea.release();

}

The full solution along with a simulation can be found at “full solution in github