https://github.com/termux/termux-packages/issues/18823

--- a/src/c11/threads.h
+++ b/src/c11/threads.h
@@ -117,7 +117,15 @@ typedef struct
 typedef pthread_cond_t  cnd_t;
 typedef pthread_t       thrd_t;
 typedef pthread_key_t   tss_t;
+#ifdef __TERMUX__
+typedef struct {
+   pthread_mutex_t mutex;
+   uint32_t init_marker;
+} mtx_t;
+#define MTX_T_INITED_MARKER 0xdeadbeef
+#else
 typedef pthread_mutex_t mtx_t;
+#endif
 #ifndef __once_flag_defined
 typedef pthread_once_t  once_flag;
 #  define ONCE_FLAG_INIT PTHREAD_ONCE_INIT
--- a/src/c11/impl/threads_posix.c
+++ b/src/c11/impl/threads_posix.c
@@ -120,7 +120,11 @@
     assert(cond != NULL);
     assert(abs_time != NULL);
 
+#ifndef __TERMUX__
     rt = pthread_cond_timedwait(cond, mtx, abs_time);
+#else
+    rt = pthread_cond_timedwait(cond, &mtx->mutex, abs_time);
+#endif
     if (rt == ETIMEDOUT)
         return thrd_timedout;
     return (rt == 0) ? thrd_success : thrd_error;
@@ -132,7 +136,11 @@
 {
     assert(mtx != NULL);
     assert(cond != NULL);
+#ifndef __TERMUX__
     return (pthread_cond_wait(cond, mtx) == 0) ? thrd_success : thrd_error;
+#else
+    return (pthread_cond_wait(cond, &mtx->mutex) == 0) ? thrd_success : thrd_error;
+#endif
 }
 
 
@@ -142,7 +150,12 @@
 mtx_destroy(mtx_t *mtx)
 {
     assert(mtx != NULL);
+#ifndef __TERMUX__
     pthread_mutex_destroy(mtx);
+#else
+    if (mtx->init_marker == MTX_T_INITED_MARKER)
+        pthread_mutex_destroy(&mtx->mutex);
+#endif
 }
 
 /*
@@ -183,13 +196,22 @@
         return thrd_error;
 
     if ((type & mtx_recursive) == 0) {
+#ifndef __TERMUX__
         pthread_mutex_init(mtx, NULL);
+#else
+        pthread_mutex_init(&mtx->mutex, NULL);
+        mtx->init_marker = MTX_T_INITED_MARKER;
+#endif
         return thrd_success;
     }
 
     pthread_mutexattr_init(&attr);
     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+#ifndef __TERMUX__
     pthread_mutex_init(mtx, &attr);
+#else
+    pthread_mutex_init(&mtx->mutex, &attr);
+#endif
     pthread_mutexattr_destroy(&attr);
     return thrd_success;
 }
@@ -199,7 +221,11 @@
 mtx_lock(mtx_t *mtx)
 {
     assert(mtx != NULL);
+#ifndef __TERMUX__
     return (pthread_mutex_lock(mtx) == 0) ? thrd_success : thrd_error;
+#else
+    return (pthread_mutex_lock(&mtx->mutex) == 0) ? thrd_success : thrd_error;
+#endif
 }
 
 static int
@@ -227,7 +253,11 @@
     {
 #ifdef EMULATED_THREADS_USE_NATIVE_TIMEDLOCK
     int rt;
+#ifndef __TERMUX__
     rt = pthread_mutex_timedlock(mtx, ts);
+#else
+    rt = pthread_mutex_timedlock(&mtx->mutex, ts);
+#endif
     if (rt == 0)
         return thrd_success;
     return (rt == ETIMEDOUT) ? thrd_timedout : thrd_error;
@@ -252,7 +282,11 @@
 mtx_trylock(mtx_t *mtx)
 {
     assert(mtx != NULL);
+#ifndef __TERMUX__
     return (pthread_mutex_trylock(mtx) == 0) ? thrd_success : thrd_busy;
+#else
+    return (pthread_mutex_trylock(&mtx->mutex) == 0) ? thrd_success : thrd_busy;
+#endif
 }
 
 // 7.25.4.6
@@ -260,7 +294,11 @@
 mtx_unlock(mtx_t *mtx)
 {
     assert(mtx != NULL);
+#ifndef __TERMUX__
     return (pthread_mutex_unlock(mtx) == 0) ? thrd_success : thrd_error;
+#else
+    return (pthread_mutex_unlock(&mtx->mutex) == 0) ? thrd_success : thrd_error;
+#endif
 }
 
 
--- a/src/util/cnd_monotonic.c
+++ b/src/util/cnd_monotonic.c
@@ -132,7 +132,11 @@
    timespec_sub_saturate(&rel_time, abs_time, &now_time);
    int rt = pthread_cond_timedwait_relative_np(&cond->cond, mtx, &rel_time);
 #else
+#ifndef __TERMUX__
    int rt = pthread_cond_timedwait(&cond->cond, mtx, abs_time);
+#else
+   int rt = pthread_cond_timedwait(&cond->cond, &mtx->mutex, abs_time);
+#endif
 #endif
    if (rt == ETIMEDOUT)
       return thrd_timedout;
@@ -151,6 +155,10 @@
                             (PCRITICAL_SECTION)mtx, INFINITE);
    return thrd_success;
 #else
+#ifndef __TERMUX__
    return (pthread_cond_wait(&cond->cond, mtx) == 0) ? thrd_success : thrd_error;
+#else
+   return (pthread_cond_wait(&cond->cond, &mtx->mutex) == 0) ? thrd_success : thrd_error;
+#endif
 #endif
 }
