查找比赛条件的方法 [英] Ways to Find a Race Condition

查看:76
本文介绍了查找比赛条件的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些带有竞争条件的代码...我知道这是一个竞争条件,因为它并不一致,而且似乎在双核计算机上更经常发生。

I have a bit of code with a race condition in it... I know that it is a race condition because it does not happen consistently, and it seems to happen more often on dual core machines.

在追踪时永远不会发生。虽然,它也有可能陷入僵局。通过分析日志记录的完成阶段(不存在和不存在),我已经可以将这个错误确定为一个功能。但是,我不知道这在功能范围内的什么地方发生。

It never happens when I'm tracing. Although, there is a possibility that it could be a deadlock as well. By analyzing stages of completion of logs where this does and does not occur, I've been able to pinpoint this bug to a single function. However, I do not know where in the scope of the function this is happening. It's not at the top level.

添加日志语句或断点将改变发生争用的时间,并防止这种情况发生。

Adding log statements or breakpoints is going to change the timing if it is a race condition, and prevent this from happening.

除了获得竞赛条件分析器之外,我是否可以使用其他任何技术来准确定位发生的情况?

Is there any technique that I can use aside from getting a race condition analyzer that will allow me to pinpoint where this is happening?

这是在Visual Studio 9中,带有C ++(非托管版本)。

This is in visual studio 9, with C++ (of the nonmanaged variety).

推荐答案

将其睡眠您代码的各个部分。即使线程(或异步代码)睡眠了几秒钟,线程安全的东西也将是线程安全的。

Put sleeps in various parts of your code. Something that is threadsafe will be threadsafe even if it (or asynchronous code) sleeps for even seconds.

这篇关于查找比赛条件的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆