[BUG] 8.0.0 broken by including a non-existing header: `zmalloc.c: fatal error: threads.h: No such file or directory`
Describe the bug
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_databases_valkey/valkey/work/compwrap/cc/opt/local/bin/gcc-mp-14 -pedantic -std=gnu11 -Wall -W -Wno-missing-field-initializers -Werror=deprecated-declarations -Wstrict-prototypes -O3 -flto=auto -fno-omit-frame-pointer -g -ggdb -arch ppc -isystem/opt/local/include/LegacySupport -isystem/opt/local/include -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram -I../deps/fpconv -DUSE_JEMALLOC -I../deps/jemalloc/include -DUSE_OPENSSL=1 -DBUILD_TLS_MODULE=0 -MMD -o zmalloc.o -c zmalloc.c
zmalloc.c:94:10: fatal error: threads.h: No such file or directory
94 | #include <threads.h>
| ^~~~~~~~~~~
compilation terminated.
make[1]: *** [zmalloc.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_databases_valkey/valkey/work/valkey-8.0.0/src'
make: *** [all] Error 2
To reproduce
Run the build.
Expected behavior
It should build, as it did before.
Additional information
macOS 10.6, gcc 14.2.0
Breakage introduced by https://github.com/valkey-io/valkey/commit/3323e422ad0c0dc81859017798cb04a9621d6522
@lipzhu @guowangy Could someone please address this?
Maybe something like this using __has_include
#if !defined(__STDC_NO_THREADS__) && defined(__has_include)
# if __has_include(<threads.h>)
# include <threads.h>
# endif
#endif
#ifndef thread_local
# define thread_local __thread
#endif
Alternatively, you could use _Thread_local instead of __thread, because a C11 compiler should support that. Including <threads.h> just gives you the thread_local macro that expands to _Thread_local, but you don't need <threads.h> to use _Thread_local.
The non-standard extension __thread will work with some pre-C11 compilers, if that's important.
#define thread_local _Thread_local seems to work in my machine (mac M3)
@jwakely do you think a #define thread_local _Thread_local is enough for this case? I tested it in some CI look like that all can pass the build, do you want to issue a fix?
#define thread_local _Thread_localseems to work in my machine (mac M3)
This works for me on macOS.
@enjoy-binbin Thank you!