Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between pthread_mutex_lock and kernel mutex_lock in linux?

Is there any relation between them? What's the difference on the implementation and the performance?

like image 885
bydsky Avatar asked Dec 06 '25 09:12

bydsky


1 Answers

There's no direct relationship.

pthread_mutex_lock() is a userspace API, implemented in the C library. On Linux, it's usually based on the kernel futex() system call.

mutex_lock() is an internal kernel API, implemented within the kernel itself and only available there. It's based around spinlocks and direct manipulation of the current task's schedulable state, usually with architecture-optimised fast paths.

It makes no sense to compare the performance because they are not interchangeable - where you can use one, you cannot use the other and vice-versa.

like image 83
caf Avatar answered Dec 08 '25 02:12

caf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!