Zephyr Project API  3.2.0
A Scalable Open Source RTOS
test_mutex_timeout_race.c File Reference
#include <zephyr/ztest.h>

Macros

#define TIMEOUT_MS   100
 
#define STACKSZ   8192
 

Functions

 K_THREAD_STACK_DEFINE (stack, 8192)
 
static void test_thread (void *p1, void *p2, void *p3)
 
 ZTEST (mutex_timeout_race_during_priority_inversion, test_mutex_timeout_error)
 Test fix for subtle race during priority inversion. More...
 
 ZTEST_SUITE (mutex_timeout_race_during_priority_inversion, NULL, NULL, NULL, NULL, NULL)
 

Variables

static struct k_mutex mutex
 
static struct k_thread thread
 

Macro Definition Documentation

◆ STACKSZ

#define STACKSZ   8192

◆ TIMEOUT_MS

#define TIMEOUT_MS   100

Function Documentation

◆ K_THREAD_STACK_DEFINE()

K_THREAD_STACK_DEFINE ( stack  ,
8192   
)

◆ test_thread()

static void test_thread ( void *  p1,
void *  p2,
void *  p3 
)
static

◆ ZTEST()

ZTEST ( mutex_timeout_race_during_priority_inversion  ,
test_mutex_timeout_error   
)

Test fix for subtle race during priority inversion.

  • A low priority thread (Tlow) locks mutex A.
  • A high priority thread (Thigh) blocks on mutex A, boosting the priority of Tlow.
  • Thigh times out waiting for mutex A.
  • Before Thigh has a chance to execute, Tlow unlocks mutex A (which now has no owner) and drops its own priority.
  • Thigh now gets a chance to execute and finds that it timed out, and then enters the block of code to lower the priority of the thread that owns mutex A (now nobody).
  • Thigh tries to the dereference the owner of mutex A (which is nobody, and thus it is NULL). This leads to an exception.
See also
k_mutex_lock()

◆ ZTEST_SUITE()

ZTEST_SUITE ( mutex_timeout_race_during_priority_inversion  ,
NULL  ,
NULL  ,
NULL  ,
NULL  ,
NULL   
)

Variable Documentation

◆ mutex

struct k_mutex mutex
static

◆ thread

struct k_thread thread
static