static void vrend_free_sync_thread(void)
{
   if (!vrend_state.sync_thread)
      return;

   mtx_lock(&vrend_state.fence_mutex);
   vrend_state.stop_sync_thread = true;
   cnd_signal(&vrend_state.fence_cond);
   mtx_unlock(&vrend_state.fence_mutex);

   thrd_join(vrend_state.sync_thread, NULL);
   vrend_state.sync_thread = 0;

   cnd_destroy(&vrend_state.fence_cond);
   mtx_destroy(&vrend_state.fence_mutex);
}
static void vrend_free_sync_thread(void)
{
   if (!vrend_state.sync_thread)
      return;

   mtx_lock(&vrend_state.fence_mutex);
   vrend_state.stop_sync_thread = true;
   cnd_signal(&vrend_state.fence_cond);
   mtx_unlock(&vrend_state.fence_mutex);

   thrd_join(vrend_state.sync_thread, NULL);
   vrend_state.sync_thread = 0;

   cnd_destroy(&vrend_state.fence_cond);
   mtx_destroy(&vrend_state.fence_mutex);
}