"initialized" asserts in os_threading.h cause problems
commit 14aed901 introduced assertions to ensure threading primitives are correctly initialized before use, but the ones in the _destroy()
trigger during some error cleanup paths.
For example, in init_all in ipc_server_process.c the global_state.lock
is initialized last. If the startup fails, teardown_all
will call os_mutex_destroy
on a mutex that was never initialized, triggering the assert.
I think there are 3 options:
- All such cases need to do conditional clean up, not calling destroy on threading primitives in such cases
- Assume calling
_destroy()
on a zeroed but uninitialized primitive is a no-op as before and remove the asserts - Always store and use the
initialized
flag even in release builds inside the threading primitives and skip destroy if they were never initialized.
The last one seems most explicit, and I think should be fine - the extra storage requirement is negligible and initializing and destroying threading primitives is not a performance sensitive path.