Goldman Sachs Interview Question
Software Engineer / DevelopersCountry: United States
1) Program stopped working. so it might have gone into deadlock. if it is c/C++ generate core file using gcore <processid> / pstack to see current stack trace of threads and who is holding the lock.
2) Inside func(), there can be code to obtain the same lock which is already locked by the calling thread or some other locks which has been taken in different order.
3) If execption is thrown, release the lock that is held in catch block
It isn't clear from your description what happened to the application, and why we'd assume that it happened in this section of the code.
- Lior October 11, 2014Assuming that the thread lock was not released, I'd guess that Func has raised an exception. It is usually best to envelope mutex lock and release with a try\except mechanism, making sure that the lock is released even if an exception is raised. (Allowing you to clean up before shutting down)