Search Results

Search found 1 results on 1 pages for 'user962800'.

Page 1/1 | 1 

  • Should i use lock.lock(): in this method?

    - by user962800
    I wrote this method whose purpose is to give notice of the fact that a thread is leaving a specific block of code A thread stands for a car which is leaving a bridge so other cars can traverse it . The bridge is accessible to a given number of cars (limited capacity) and it's one way only. public void getout(int diection){ // release the lock semaphore.release(); try{ lock.lock(); //access to shared data if(direction == Car.NORTH) nNordTraversing--; //decreasing traversing threads else nSudTraversing--; bridgeCond.signal(); }finally{ lock.unlock(); } } My question is: should I use lock.lock(); or it's just nonsense? thanks in advance

    Read the article

1