Goldman Sachs Interview Question for Software Engineer / Developers


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

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.

Assuming 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)

- Lior October 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

And about part 3 -
I'd put another print after Func, to check whether the error was inside Func or not. And if it was, add more prints inside Func recursively until I find the specific line which generated the exception.

- Lior October 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

might be some problem inside function and it is not able to handle exception occurs inside the fun

- raj October 31, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The application perhaps is in a deadlock. Lock wasn't released because of an exception in func(). Another thread waiting for the unreleased lock is kept in waiting state forever.

To avoid this situation, surround func() in a try, catch. Release the lock when an exception is thrown.

- P December 19, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Actually CalledFunc() should be present in a try-catch-finally block. If you are using your own lock objects, they must be explicitly released in the finally block.

- Murali Mohan July 26, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Func() might have called CalledFunc() again recursively. Which caused a case for need of re-entrant lock. So in this case same thread is waiting for the lock which was already acquired by it and hence deadlock.

- Anonymous March 25, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Func() might have called CalledFunc() again recursively. Which caused a case for need of re-entrant lock. So in this case same thread is waiting for the lock which was already acquired by it and hence deadlock.

So using re-entrant protection lock might help if that's the issue.

- awagh1 March 25, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- Sugan January 10, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More