Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@synchronized vs. NSLock Instance vs. pthread_mutex_t

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

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

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.

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

like image 549
ArtSabintsev Avatar asked Feb 02 '23 06:02

ArtSabintsev


1 Answers

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.

like image 160
Hot Licks Avatar answered Feb 05 '23 00:02

Hot Licks