On 3/12/22 20:59, Warner Losh wrote:
FreeBSD's pthread_mutex is shared between the kernel and user land. So it does a compare and set to take the lock. Uncontested and unheld locks will mean we've taken the lock and return. Contested locks are kicked to the kernel to wait. When userland releases the lock it signals the kernel to wakeup via a system call. The kernel then does a cas to try to acquire the lock. It either returns with the lock held, or goes back to sleep. This we have atomics operating both in the kernel (via standard host atomics) and userland atomics done via start/end_exclusive.
You need to use standard host atomics for this case. r~