Adobe Interview Question
Developer Program EngineersCountry: India
Interview Type: In-Person
improving Anonymous idea
Using Binary Semaphore bMutex where
false means no thread has acquired.
true means thread has acquired a lock.
static bool bMutex = false;
int Signal()
{
if( bMutex == false)
{
bMutex = true;
return 1;
}
else
{
WaitforSignal();
}
}
//Thread will release the lock and go to sleep mode untill signalled
int Wait()
{
if( bMutex == true)
{
bMutex = false
}
SignalWaitingThreads();
return 1;
}
This pseudo code could be improved
this can be done using a static bool variable
- abc July 04, 2012lets say the mutex has to be around task f1()
void mutex()
{
static bool bMutexVal = false;
}