Add gettid() for proper thread affinity on Linux