无锁多线程编程是否使一切变得容易? [英] Is lock free multithreaded programming making anything easier?

查看:159
本文介绍了无锁多线程编程是否使一切变得容易?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只读了一点有关此主题的内容,但是似乎唯一的好处是解决争用问题,但是它对死锁问题没有任何重要影响,因为无锁的代码是如此之小且基本. (fifos,lifos,hash),从来没有死锁问题.

这一切都与性能有关-对吗?

解决方案

(据我所知)无锁编程始终与性能有关,否则,在大多数情况下使用锁更为简单,因此更可取. /p>

但是请注意,使用无锁编程,您最终可能会将死锁换成实时锁定,这很难诊断,因为我所知没有工具专门用于诊断它(尽管在那儿我可能是错的).

我要说的是,只有在必须的时候才走无锁的道路.就是说,您有一个场景,其中您的锁竞争激烈,这会损害您的性能. (如果它没有损坏,请不要修复它.)

I only read a little bit about this topic, but it seems that the only benefit is to get around contention problems but it will not have any important effect on the deadlock problem as the code which is lock free is so small and fundamental (fifos, lifos, hash) that there was never a deadlock problem.

So it's all about performance - is this right?

解决方案

Lock-free programming is (as far as I can see) always about performance, otherwise using a lock is in most cases much simpler, and therefore preferable.

Note however that with lock-free programming you can end up trading deadlock for live-lock, which is a lot harder to diagnose since no tools that I know of are designed to diagnose it (although I could be wrong there).

I'd say, only go down the path of lock-free if you have to; that is, you have a scenario where you have a heavily contended lock that is hurting your performance. (If it ain't broke, don't fix it).

这篇关于无锁多线程编程是否使一切变得容易?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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