@synchronized vs. NSLock Instance vs. pthread_mutex_t [英] @synchronized vs. NSLock Instance vs. pthread_mutex_t

查看:159
本文介绍了@synchronized vs. NSLock Instance vs. pthread_mutex_t的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在观看多线程教学视频(2岁),表示

I was watching a (2-year old) tutorial video on multithreading that stated that


  • NSLock实例 @synchronized

  • pthread_mutex_t 比使用 NSLock实例快两倍比 @synchronized 快6倍)

  • NSLock instance is 3x faster than using @synchronized
  • pthread_mutex_t is 2x faster than an NSLock instance (effectively 6x faster than @synchronized)

这是真的吗?我没有找到任何有权威的声明,但是我只是想在StackOverflow为你的意见和可能的坚实证明来轮询你一些。

Is this true? I haven't found anything that states with authority that it is, but I just wanted to poll some of you over at StackOverflow for your opinion and maybe solid proof.

谢谢!

虽然我已经接受了正确答案,但此问题的未来查看者会发现此文章有帮助: http://perpendiculo.us/?p=133

While I've already accepted the correct answer, future viewers of this question will find this article to be helpful: http://perpendiculo.us/?p=133

推荐答案

重要的是要记住, @synchronized 包括必要的try / catch逻辑来释放异常中的锁。一旦你添加了这个逻辑,性能差异(在整体量级上不是很大)可能会明显减少。

It's important to keep in mind that @synchronized includes the necessary try/catch logic to release the lock in an exception. Once you add that logic the performance difference (which is not great in overall magnitude) will probably diminish significantly.

这篇关于@synchronized vs. NSLock Instance vs. pthread_mutex_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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