feat(#494): C11 threads.h backend with auto-detection and fallback#503
Merged
feat(#494): C11 threads.h backend with auto-detection and fallback#503
Conversation
Add thread_c11.c implementing C11 thrd_create/mtx_*/cnd_* API with a trampoline to bridge void*(*)(void*) to int(*)(void*). Update thread.h with 3-tier ifdef cascade (C11 > Win32 > POSIX). Meson detects C11 support via cc.links() with actual thrd_create call. io_adapter.c uses call_once + mtx_init for lazy mutex init on C11 path with error flag propagation. POSIX and MSVC backends unchanged.
Replace direct pthread_create/pthread_join/pthread_t usage in test_io_adapter_concurrent.c and test_mem_ledger.c with the thread.h abstraction layer (thread_create/thread_join/thread_t). Enables these tests to run on the C11 threads backend without modification.
Document C11 <threads.h> backend addition with auto-detection and POSIX/MSVC fallback under [Unreleased] section.
a2e7e41 to
f70f6cd
Compare
Replace hardcoded thread_posix.c/thread_msvc.c selection in tests/meson.build and bench/meson.build with wirelog_thread_src from the parent scope. Fixes type mismatch when C11 threads backend is active (mtx_t vs pthread_mutex_t under TSan).
TSan does not track happens-before through glibc call_once for non-atomic variables. Use atomic_store/atomic_load on the init flag to make the synchronization explicit and TSan-clean.
TSan only intercepts POSIX pthread calls; C11 <threads.h> functions (thrd_create, mtx_lock) are uninstrumented, causing false SEGV. Split threads option into native (auto-detect C11/POSIX) and posix (force pthreads). CI TSan steps now use -Dthreads=posix to ensure proper instrumentation. Remove disabled option since threading is always required.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wirelog/thread_c11.cimplementing C11<threads.h>API (thrd_create/mtx_*/cnd_*) with trampoline to bridgevoid*(*)(void*)toint(*)(void*)signaturewirelog/thread.hwith 3-tier#ifdefcascade:WL_HAVE_C11_THREADS>_WIN32> POSIXcc.links()with actualthrd_createcall (not just header check)io_adapter.c: Add C11call_once+mtx_initwith error flag propagation for lazy mutex inittest_io_adapter_concurrent.candtest_mem_ledger.cfrom rawpthread_*tothread.habstractionPlatform activation matrix
<threads.h><threads.h><threads.h>Scope
Threading migration only (DoD items 1-2).
_GNU_SOURCE/qsort_r/__builtin_*intrinsics deferred to separate issue.Test plan
cc.links()returns YES on Linux GCC, NO on macOS Apple Clangcall_oncepath: error flag propagation verifiedpthread_create/pthread_joinreferencesRalplan consensus
call_once+mtx_initis correct C11 patternCloses #494