Skip to content

Commit 28d3db1

Browse files
committed
ports/stm32: Update mutex typedef to use k_sem for Zephyr threading.
Changed mp_thread_mutex_t and mp_thread_recursive_mutex_t to use struct k_sem instead of struct k_mutex. This change is required to fix GIL deadlock issues with Zephyr threading, as k_mutex has ownership tracking that prevents cross-thread lock/unlock operations needed by the GIL. This matches the reference implementation in ports/zephyr and enables proper multi-threaded operation with shared locks and thread arguments. Signed-off-by: Andrew Leech <[email protected]>
1 parent 57e6e61 commit 28d3db1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ports/stm32/mpthreadport_zephyr.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@
3131

3232
#include <zephyr/kernel.h>
3333

34-
// Mutex types using Zephyr k_mutex
34+
// Mutex types using Zephyr k_sem (binary semaphore)
35+
// Need a binary semaphore so a lock can be acquired on one Python thread
36+
// and then released on another (required for GIL).
3537
typedef struct _mp_thread_mutex_t {
36-
struct k_mutex handle;
38+
struct k_sem handle;
3739
} mp_thread_mutex_t;
3840

3941
typedef struct _mp_thread_recursive_mutex_t {
40-
struct k_mutex handle;
42+
struct k_sem handle;
4143
} mp_thread_recursive_mutex_t;
4244

4345
// Threading functions (implemented in extmod/zephyr_kernel/mpthread_zephyr.c)

0 commit comments

Comments
 (0)