C语言程序设计:用pthread的调试 [英] C Programming: Debugging with pthreads

查看:125
本文介绍了C语言程序设计:用pthread的调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个最难的事情对我来说,一开始适应是我第一次强烈的编程经验与我是用来了解什么code的下一行要运行将是C. Pthreads并且我的大部分调试技术围绕这种期望。

One of the hardest things for me to initially adjust to was my first intense experience programming with pthreads in C. I was used to knowing exactly what the next line of code to be run would be and most of my debugging techniques centered around that expectation.

有什么好的技术在C pthread的调试?你能提出个人的方法没有任何附加工具,您使用的工具,或其他任何东西,可以帮助您进行调试。

What are some good techniques to debugging with pthreads in C? You can suggest personal methodologies without any added tools, tools you use, or anything else that helps you debug.

P.S。我用在Linux GCC我的C语言编程,但不要让这必然抑制你的答案

P.S. I do my C programming using gcc in linux, but don't let that necessarily restrain your answer

推荐答案

Valgrind的是找到比赛条件和pthread API一个极好的工具误用。它使程序存储器模型(也许是共享资源)的访问,并将检测丢失锁,即使错误是良性的(这当然意味着将彻底意外在稍后一点变得不那么良性)。

Valgrind is an excellent tool to find race conditions and pthreads API misuses. It keeps a model of program memory (and perhaps of shared resources) accesses and will detect missing locks even when the bug is benign (which of course means that it will completely unexpectedly become less benign at some later point).

要使用它,你调用的valgrind --tool = helgrind 这里是它的手册。此外,还有的valgrind --tool = DRD 手动)。 Helgrind和DRD使用不同的模型,使他们检测重叠,但可能不同的错误。误报也可能会出现。

To use it, you invoke valgrind --tool=helgrind, here is its manual. Also, there is valgrind --tool=drd (manual). Helgrind and DRD use different models so they detect overlapping but possibly different set of bugs. False positives also may occur.

总之,Valgrind的拯救了无数个小时的调试(不是所有的人,虽然我:)。

Anyway, valgrind has saved countless hours of debugging (not all of them though :) for me.

这篇关于C语言程序设计:用pthread的调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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