9628001
9628001

Reputation: 529

FIFO code explanation

Is the following code an example of a FIFO ordering?

The problem consists of implementing a FIFO queue.

In a nutshell: a random number of cars (going north or south) drive along a two lane road. They must traverse a bridge which is one way.

The bridge access is dependent on the arrival time. First come First served.

Can I say that through this statement

semaphore = new Semaphore(capacita,true); 

cars cross the bridge according their arrival order?

Here I can't figure out how it works and how it can be related to the previous statement

lock = new ReentrantLock(true); 

Can someone help me?

thanks

public Ponte(int capacita){
        nNordTraversing = 0;    
        nSudTraversing = 0;     
        nNordWaiting = 0;   
        nSudWaiting = 0;    

        semaphore = new Semaphore(capacita,true); 


        lock = new ReentrantLock(true);           

        waitingCond = lock.newCondition();
        bridgeCond = lock.newCondition();
    }

Upvotes: 0

Views: 492

Answers (1)

abon999
abon999

Reputation: 336

your code is strange, and i don't understand them just with this part. You can easily found a correct algorithm on the internet for resolve that with semaphore.

for example : http://cboard.cprogramming.com/c-programming/119766-semaphore-algorithm.html this problem looks like your! Good luck for searching!

Upvotes: 1

Related Questions