Goldman Sachs Interview Question
Software Engineer / DevelopersTeam: Trading System
Country: United States
I'm not sure if this is particular to any language, but I see this in the C++ section, so I'll answer accordingly.
1. A number of things may have happened in func(). I would check out the call stack and make sure that the function was the last thing that called. Once I have confirmed that, I would investigate and make sure func() does not throw any exceptions or get caught in an infinite loop (or any other basic errors like referencing nulls). There is a possibility of a deadlock (but only in the case if there is a static or member mutex).
2. Again, we do not know for sure what has happened in func() with what is given, but due to the nature of this question, the interviewer is probably implying that func() has thrown an exception.
3. In C++, the correct way to handle this is through the use of RAII. A number of solutions will work including scoped locks, mutex with functors, or narrowing the scope of that lock to known parts of code where you KNOW exceptions will not be thrown. A try/catch will not help you in C++. However, in Java, simply use a try/finally block to ensure forward movement in the code.
It stopped responding as soon as the function acquired the lock. This suggests a deadlock situation.
The most likely situation is that Func() needed a resource and didn't get it, so it couldn't proceed further. On the other hand, other threads might be waiting for Func() to end so that it can release its locks.
1> As the application has stopped means that deadlock situation had occurred. Somehow your thread lock fails to lock the shared resources or the context switching happened in such a way that Func could not reserve the resource necessary for its normal execution.
- hprem991 October 07, 20142> Func is using certain resources with is currently owned by other thread.
3> Handle that exception by releasing all the acquired resources than call sync call to Func to deliver the service.. other way to fix is to handle inside the function itself for resource constraints .