C++ 关于调试、多线程的面试题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/291745/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:23:03  来源:igfitidea点击:

Interview question about debugging, multithreading

c++debugging

提问by anand

I had telephone interview question yesterday. The interviewer asked me if I had faced any challenging debugging issue? I told him I once faced a problem debugging someone else's code and it took me 3-4 days to solve that. I used Windbg, symbols and a crash dump to solve the problem.

我昨天有电话面试问题。面试官问我是否遇到过任何具有挑战性的调试问题?我告诉他我曾经在调试别人的代码时遇到过问题,我花了 3-4 天的时间来解决这个问题。我使用 Windbg、符号和故障转储来解决问题。

Now is this enough to tell? What is interviewer expecting?

现在这足以说明吗?面试官期待什么?

I don't know what else to tell, I faced that problem quite some time back and can't explain all details...

我不知道还能说什么,很久以前我就遇到过这个问题,无法解释所有细节......

This question is very very common and I am not sure what the right answer to it?

这个问题非常非常普遍,我不确定它的正确答案是什么?

One more question that is very common:

还有一个很常见的问题:

Have you worked on multi-threaded applications? How can you find out deadlock? Answer: Well to find deadlock we can look at snapshot of process in memory and can look at threads that are waiting.

您是否从事过多线程应用程序?你怎么能找出死锁?答:为了找到死锁,我们可以查看内存中进程的快照,并查看正在等待的线程。

Then next question: What can you do to avoid deadlock?

那么下一个问题:你能做些什么来避免死锁?

  1. Use waitformultipleobjects
  2. Maintain sequence of critical sections
  1. 使用等待多个对象
  2. 维护关键部分的顺序

What do you guys say?

你们怎么说?

回答by Gavin Miller

The general rule for interviews is to use the STAR model (my co-op coordinator is going to be proud here...):

面试的一般规则是使用 STAR 模型(我的合作社协调员在这里会感到自豪......):

S- Describe the situation you were in
T- Explain the task, providing enough info so that the interviewer understands the problem.
A- Describe the action you took to solve the problem.
R- What were the results of your actions

S- 描述你当时的情况
T- 解释任务,提供足够的信息,以便面试官理解问题。
A- 描述您为解决问题所采取的行动。
R- 你的行为的结果是什么

If you provide a concise answer, not too short or too long, 99.9% of interviewers will be satisfied.

如果你提供一个简洁的答案,不要太短或太长,99.9%的面试官都会满意。

回答by Lalatendu

One of the main reason deadlock can occur in a multi-threaded application is circular wait where two different threads holding two resources and each of them wait for the other resource. The other conditions deadlock to occur is no preemption, hold-and-wait and mutual-exclusion.

在多线程应用程序中可能发生死锁的主要原因之一是循环等待,其中两个不同的线程持有两个资源,每个线程都等待另一个资源。发生死锁的其他条件是没有抢占、保持等待和互斥。

The best way to avoid deadlock is to maintain lock order. In other words let the threads able to get the lock in a particular order. This will restrict the threads to come into deadlock.

避免死锁的最好方法是维护锁顺序。换句话说,让线程能够以特定的顺序获得锁。这将限制线程进入死锁。

回答by gbjbaanb

Interview questions (well, the good ones at least) are not concerned about you telling the knowledge you have, its explaining to the interviewer's satisfaction that you actually do know it.

面试问题(好吧,至少是好的问题)并不关心你讲述你所拥有的知识,而是向面试官解释你确实知道这些知识而感到满意。

So, whilst you could explain the full intricacies of windbg, he won't care. He will care that you know what to do and believes you. You only have to supply enough information to satisfy that. The alternative is to actually debug something in front of him to prove it and interviews never last that long :)

所以,虽然你可以解释 windbg 的全部复杂性,但他不会在意。他会关心你知道该怎么做并相信你。你只需要提供足够的信息来满足这一点。另一种方法是在他面前实际调试一些东西来证明这一点,而面试永远不会持续那么久:)

So I think (from what you've said) that you know what you're talking about, that you do have that experience, that you could do it again. So lets move on to the next question to find out a little more about what else you know.

所以我认为(根据你所说的)你知道你在说什么,你确实有那种经历,你可以再做一次。因此,让我们继续下一个问题,以了解更多关于您所知道的信息。

Sometimes you many answer in a way that's a bit ambiguous, no problem - we'll just ask another one and another until we find out whether we think you're good enough for the role, or not.

有时你们会以一种有点模棱两可的方式回答,没问题——我们只会问一个又一个,直到我们发现我们认为你是否适合这个角色。

Interviews are only like exams in that its your working the interviewer is interested in, not the result.

面试只是像考试一样,面试官感兴趣的是你的工作,而不是结果。