线程安全测试
我目前使用谷歌的 gtest 来编写我的单元测试,但它看起来不能测试线程安全性(即从多个线程访问某些内容并确保其行为符合规范)。
你用什么来测试线程安全?我想要跨平台的东西,但是,它至少必须在 Windows 上运行。
谢谢你!
I currently use googles' gtest to write my unit tests, but it doesn't look like it can test thread-safety (that is, accessing something from multiple threads and ensuring it behaves according to spec).
What do you use to test thread safety? I'd like something cross-platform, but, it definitely has to work on Windows atleast.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果多线程代码不能立即、明显地、被证明是正确的,那么它几乎肯定是错误的。如果是的话,您不需要测试它。
说真的:共享可变状态应该是极其本地化和罕见的,并且执行它的类应该是明显正确的。
您的线程通常应该通过安全原语(例如线程安全工作队列)进行交互。如果您的代码周围散布着大量数据结构,每个数据结构都有自己的锁定策略,那么您的代码几乎肯定包含死锁和竞争条件。大量的测试工作只能发现一些问题。
If multithreaded code isn't immediately, obviously, provably correct then it is almost certainly wrong. And if it is, you don't need to test it.
Seriously: shared mutable state should be extremely localised and rare, and the classes that do it should be demonstrably correct.
Your threads should normally interact via safe primitives (eg a thread-safe work queue). If you have lots of data structures scattered around your code each with its own locking strategy then your code almost certainly contains deadlocks and race conditions. A big testing effort will only find some of the problems.