Code example for Semaphore

Methods: acquire, availablePermits, release, tryAcquire

0
		 
		return packedReturn;
	} 
	 
	public void updateDisplay() { 
		Log.i("Freeciv", String.format("Updating display, acquiring display lock: Avail: %d: TID: %d", displayLock.availablePermits(), Thread.currentThread().getId()));
		try { 
			displayLock.acquire();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		} 
		if (mainActivity != null) {
			mainActivity.updateMapview(nativeBuffer, displayLock);			
		} else { 
			Log.i("Freeciv", "Premature release");
			displayLock.release();
		} 
		Log.i("Freeciv", "Done updating display, acquiring to sync with gui thread");
		try { 
			displayLock.tryAcquire(100, TimeUnit.MILLISECONDS);
		} catch (InterruptedException e) {
			//Ignore 
			Log.i("Freeciv","Gave up on display lock");			
		} 
		Log.i("Freeciv", String.format("acquired, now release lock: Avail: %d TID: %d", displayLock.availablePermits(), Thread.currentThread().getId()));
		displayLock.release();
		Log.i("Freeciv", "released");
	}