[RTEMS Project] #4526: pthread_cond_wait() causes an INTERNAL_ERROR_BAD_THREAD_DISPATCH_DISABLE_LEVEL

RTEMS trac trac at rtems.org
Fri Oct 8 21:00:00 UTC 2021


#4526: pthread_cond_wait() causes an
INTERNAL_ERROR_BAD_THREAD_DISPATCH_DISABLE_LEVEL
---------------------------+--------------------
  Reporter:  Pat Bernardi  |      Owner:  (none)
      Type:  defect        |     Status:  new
  Priority:  normal        |  Milestone:
 Component:  posix         |    Version:  6
  Severity:  major         |   Keywords:
Blocked By:                |   Blocking:
---------------------------+--------------------
 Calling `pthread_cond_wait()` with a mutex using the priority ceiling
 protocol causes the kernel to terminate with an
 `INTERNAL_ERROR_BAD_THREAD_DISPATCH_DISABLE_LEVEL` fatal code.

 The following C program reproduces the error with the latest Git master
 checkout (f6385b4edc5d0cc6626783c7920c521622796b4b) on AArch64:

 {{{
 #!c
 #include <pthread.h>

 void *
 POSIX_Init (void *argument)
 {
   pthread_mutex_t mutex;
   pthread_mutexattr_t mutex_attr;
   pthread_cond_t cond;

   pthread_mutexattr_init (&mutex_attr);
   pthread_mutexattr_setprotocol (&mutex_attr, PTHREAD_PRIO_PROTECT);
   pthread_mutex_init (&mutex, &mutex_attr);
   pthread_cond_init (&cond, NULL);
   pthread_mutex_lock (&mutex);
   pthread_cond_wait (&cond, &mutex);

   return 0;
 }

 /* configuration */

 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
 #define CONFIGURE_UNLIMITED_OBJECTS
 #define CONFIGURE_UNIFIED_WORK_AREAS
 #define CONFIGURE_INIT

 #include <rtems/confdefs.h>

 }}}

 A debugging session shows that `_Thread_Dispatch_disable_critical` is
 called twice within `_Thread_queue_Enqueue`:

 {{{
 Thread 1 hit Breakpoint 2, _Thread_Dispatch_disable_with_CPU () at
 src/kernel/cpukit/include/rtems/score/threaddispatch.h:171
 4: cpu_self->thread_dispatch_disable_level = 0
 ++bt
 #0  _Thread_Dispatch_disable_with_CPU () at
 src/kernel/cpukit/include/rtems/score/threaddispatch.h:171
 #1  _Thread_Dispatch_disable_critical () at
 src/kernel/cpukit/include/rtems/score/threaddispatch.h:195
 #2  _Thread_queue_Dispatch_disable () at
 src/kernel/cpukit/include/rtems/score/threadqimpl.h:449
 #3  _Thread_queue_Enqueue () at
 src/kernel/cpukit/score/src/threadqenqueue.c:432
 #4  _POSIX_Condition_variables_Wait_support () at
 src/kernel/cpukit/posix/src/condwaitsupp.c:148
 #5  pthread_cond_wait () at src/kernel/cpukit/posix/src/condwait.c:54
 ++c

 Thread 1 hit Breakpoint 2, _Thread_Dispatch_disable_with_CPU () at
 src/kernel/cpukit/include/rtems/score/threaddispatch.h:171
 4: cpu_self->thread_dispatch_disable_level = 1
 ++bt
 #0  _Thread_Dispatch_disable_with_CPU () at
 src/kernel/cpukit/include/rtems/score/threaddispatch.h:171
 #1  _Thread_Dispatch_disable_critical () at
 src/kernel/cpukit/include/rtems/score/threaddispatch.h:195
 #2  _Thread_queue_Surrender_priority_ceiling () at
 src/kernel/cpukit/score/src/threadqenqueue.c:813
 #3  _POSIX_Mutex_Ceiling_surrender () at
 src/kernel/cpukit/include/rtems/posix/muteximpl.h:400
 #4  pthread_mutex_unlock () at
 src/kernel/cpukit/posix/src/mutexunlock.c:93
 #5  _POSIX_Condition_variables_Mutex_unlock () at
 src/kernel/cpukit/posix/src/condwaitsupp.c:40
 #6  _POSIX_Condition_variables_Enqueue_no_timeout () at
 src/kernel/cpukit/posix/src/condwaitsupp.c:59
 #7  _Thread_queue_Enqueue () at
 src/kernel/cpukit/score/src/threadqenqueue.c:435
 #8  _POSIX_Condition_variables_Wait_support () at
 src/kernel/cpukit/posix/src/condwaitsupp.c:148
 #9  pthread_cond_wait () at src/kernel/cpukit/posix/src/condwait.c:54
 }}}

 We found this regression was introduced by commit
 9c0591f12d450401746bc0bf7cd7a0e0b14a5f3b.

--
Ticket URL: <http://devel.rtems.org/ticket/4526>
RTEMS Project <http://www.rtems.org/>
RTEMS Project


More information about the bugs mailing list