backend: move freeing of td->mutex to main thread