diff --git a/sched/pthread/pthread_mutexlock.c b/sched/pthread/pthread_mutexlock.c index 251f071b474..c39a384bed4 100644 --- a/sched/pthread/pthread_mutexlock.c +++ b/sched/pthread/pthread_mutexlock.c @@ -170,6 +170,7 @@ int pthread_mutex_lock(FAR pthread_mutex_t *mutex) else if (mutex->pid > 0 && sched_gettcb(mutex->pid) == NULL) { DEBUGASSERT(mutex->pid != 0); /* < 0: available, >0 owned, ==0 error */ + DEBUGASSERT((mutex->flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0); /* A thread holds the mutex, but there is no such thread. POSIX * requires that the 'robust' mutex return EOWNERDEAD in this case. @@ -177,7 +178,8 @@ int pthread_mutex_lock(FAR pthread_mutex_t *mutex) * fo fix the mutex. */ - ret = EOWNERDEAD; + mutex->flags |= _PTHREAD_MFLAGS_INCONSISTENT; + ret = EOWNERDEAD; } else { diff --git a/sched/pthread/pthread_mutextrylock.c b/sched/pthread/pthread_mutextrylock.c index 630de9e5fd3..683909c8594 100644 --- a/sched/pthread/pthread_mutextrylock.c +++ b/sched/pthread/pthread_mutextrylock.c @@ -157,6 +157,7 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex) if (mutex->pid > 0 && sched_gettcb(mutex->pid) == NULL) { DEBUGASSERT(mutex->pid != 0); /* < 0: available, >0 owned, ==0 error */ + DEBUGASSERT((mutex->flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0); /* A thread holds the mutex, but there is no such thread. * POSIX requires that the 'robust' mutex return EOWNERDEAD @@ -164,7 +165,8 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex) * call pthread_mutx_consistent() fo fix the mutex. */ - ret = EOWNERDEAD; + mutex->flags |= _PTHREAD_MFLAGS_INCONSISTENT; + ret = EOWNERDEAD; } /* The mutex is locked by another, active thread */