pthread_mutex_lock(), EDEADLK and thread ID

From: Rozhuk Ivan <>
Date: Wed, 28 Jul 2021 03:55:59 +0300

We have some product based on FreeBSD 12.2 that running in different places and
environments, more than 5 years.

At one place we got EDEADLK some times then calling pthread_mutex_lock().
This happen to often: 1-4 times per 10 minutes.
Code designed to call abort() and generate coredump.
So we mostly sure that this was not happen in other places in past.

I know that we run as VmWare guest and can ask more details.

In lib/libthr/thread/thr_mutex.c
static int
mutex_lock_sleep(struct pthread *curthread, struct pthread_mutex *m,
    const struct timespec *abstime)
	uint32_t id, owner;
	int count, ret;

	id = TID(curthread);
	if (PMUTEX_OWNER_ID(m) == id)
		return (mutex_self_lock(m, abstime));

mutex_self_lock() may return EDEADLK for PTHREAD_MUTEX_ERRORCHECK mutex type, which is default.

Is it possible that "id = TID(_get_curthread());" some how changed to ID some other thread that lock mutex in past?
Received on Wed Jul 28 2021 - 00:55:59 UTC

Original text of this message