Microsoft

  www.microsoft.com
Work in HR? Unlock Free Profile

Microsoft Senior Software Development Engineer In Test (SDET) Interview Question

I interviewed in Redmond, WA and was asked:
"Implement a counting semaphore using only binary mutexes"
Tags: programming, c++
Add Tags [?]
Answer

Part of a Senior Software Development Engineer In Test (SDET) Interview Review - one of 3,371 Microsoft Interview Reviews

Answers & Comments

1
of 1
vote
int counter = 0;
mutex m;

sempahore_increase()
{
lock(m);
counter++;
unlock(m);
}

semaphore_decrease()
{
while (true)
{
lock(m);
if (counter)
{
counter--;
unlock(m);
sleep(1000);
return;
}
unlock(m);
}
}
- Azh on Sep 9, 2010

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.