In thread.h thread_mutex_lock() doesn't behave the same on Windows as on Linux/macOS. On Windows it is recursive, meaning you can double-lock a mutex on the same thread, but on Linux as it is it will deadlock. My personal solution is making the pthread one also recursive by replacing pthread_mutex_init( (pthread_mutex_t*) mutex, NULL ); with:
pthread_mutexattr_t ma;
pthread_mutexattr_init(&ma);
pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init((pthread_mutex_t *) mutex, &ma);
pthread_mutexattr_destroy(&ma);