diff --git a/emper/Runtime.cpp b/emper/Runtime.cpp
index ad79ad43996e49fea2c6d1afcfb52cab77916416..0ca865bd2ddf2f4ce463cda408feb25876a4747f 100644
--- a/emper/Runtime.cpp
+++ b/emper/Runtime.cpp
@@ -8,6 +8,7 @@
 // Non portable.
 #include <sched.h>				// for cpu_set_t, CPU_SET, CPU_ZERO
 #include <sys/sysinfo.h>	// for get_nprocs
+#include <unistd.h>
 
 #include <cstdlib>	// for rand, srand, abort
 #include <cstring>
@@ -48,8 +49,10 @@
 #include <urcu.h>	 // for rcu_register_thread
 #endif
 
-#include <syscall.h>	// for SYS_gettid
-#include <unistd.h>		// for syscall
+#ifndef EMPER_HAS_GETTID
+#include <syscall.h>
+#define gettid() (syscall(SYS_gettid))
+#endif
 
 std::mutex Runtime::currentRuntimeMutex;
 Runtime* Runtime::currentRuntime;
@@ -249,7 +252,7 @@ auto Runtime::workerLoop(Worker* worker) -> void* {
 		workerIo->setWorkerIo(worker);
 	}
 
-	LOGD("Worker loop started by thread " << syscall(SYS_gettid));
+	LOGD("Worker loop started by thread " << gettid());
 
 	int oldType;
 	errno = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldType);
diff --git a/emper/meson.build b/emper/meson.build
index 96c3737fd81c37517173d08b7a10f37131d5739a..5e827d84a94854a66dc5a45437c101080a7c237d 100644
--- a/emper/meson.build
+++ b/emper/meson.build
@@ -1,3 +1,6 @@
+cpp_has_gettid = cpp_compiler.has_function('gettid', prefix: '#include<unistd.h>')
+conf_data.set('EMPER_HAS_GETTID', cpp_has_gettid)
+
 emper_asm_sources = [ 'ContextAsm.nasm' ]
 nasm = find_program('nasm')
 # mesons's nasm support currently means using generator()