 	{
 		HLTError("Error getting CUDA Device Count");
 		fgGPUUsed = 0;
+		ReleaseGlobalLock(semLock);
 		return(1);
 	}
 	if (fDebugLevel >= 2) HLTInfo("Available CUDA devices:");


#ifdef R__WIN32
	HANDLE* semLock = new HANDLE;
	*semLock = CreateSemaphore(NULL, 0, 1, "AliceHLTTPCCAGPUTrackerInitLock");
	WaitForSingleObject(*semLock, INFINITE);
#else
	sem_t* semLock = sem_open("AliceHLTTPCCAGPUTrackerInitLock", O_CREAT);
	sem_wait(semLock);
#endif

	if (fgGPUUsed)
	{
	    HLTWarning("CUDA already used by another AliHLTTPCCAGPUTracker running in same process");
	    return(1);
	}
	fgGPUUsed = 1;

#else
	sem_t* pSem = (sem_t*) sem;
	sem_post(pSem);
	sem_unlink(SemLockName);
#endif
}

