Inside pthread_cond_signal() is called each time mtx_init(). mtx_init() is created the semaphore in any case: `mutex->sem = xSemaphoreCreateBinary (); ` This condition should be avoided: `if ( !mutex-> sem ) mutex->sem = xSemaphoreCreateBinary ();` In addition, all of the objects by malloc () must be reset. Used calloc () or memcpy(0) after malloc().