简体   繁体   English

@synchronized 与 NSLock 实例与 pthread_mutex_t

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

I was watching a (2-year old) tutorial video on multithreading that stated that我正在观看一个(2 岁的)关于多线程的教程视频,其中指出

  • NSLock instance is 3x faster than using @synchronized NSLock 实例比使用@synchronized快 3 倍
  • pthread_mutex_t is 2x faster than an NSLock instance (effectively 6x faster than @synchronized ) pthread_mutex_tNSLock 实例快 2 倍(实际上比@synchronized快 6 倍)

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.我还没有找到任何有权威的说法,但我只是想在 StackOverflow 上对你们中的一些人进行投票,征求你们的意见,也许还有确凿的证据。

Thanks!谢谢!

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虽然我已经接受了正确答案,但这个问题的未来观众会发现这篇文章很有帮助: http://perpendiculo.us/?p=133

It's important to keep in mind that @synchronized includes the necessary try/catch logic to release the lock in an exception.请务必记住, @synchronized包含必要的 try/catch 逻辑以在异常中释放锁。 Once you add that logic the performance difference (which is not great in overall magnitude) will probably diminish significantly.一旦你添加了这个逻辑,性能差异(总体上不是很大)可能会显着减少。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM