Skip to content

Build fails on Linux when threads are disabled because this_thread::get_id() is called #14189

@zmajeed

Description

@zmajeed

What happens?

DuckDB build fails when configured with cmake -D DISABLE_THREADS=1 because the following code doesn't check DUCKDB_NO_THREADS macro

// src/parallel/task_scheduler.cpp

idx_t TaskScheduler::GetEstimatedCPUId() {
#if defined(EMSCRIPTEN)
	// FIXME: Wasm + multithreads can likely be implemented as
	//   return return (idx_t)std::hash<std::thread::id>()(std::this_thread::get_id());
	return 0;
#else
	// this code comes from jemalloc
#if defined(_WIN32)
	return (idx_t)GetCurrentProcessorNumber();
#elif defined(_GNU_SOURCE)
	auto cpu = sched_getcpu();
	if (cpu < 0) {
		// fallback to thread id
		return (idx_t)std::hash<std::thread::id>()(std::this_thread::get_id());
	}
	return (idx_t)cpu;
#elif defined(__aarch64__) && defined(__APPLE__)
	/* Other oses most likely use tpidr_el0 instead */
	uintptr_t c;
	asm volatile("mrs %x0, tpidrro_el0" : "=r"(c)::"memory");
	return (idx_t)(c & (1 << 3) - 1);
#else
	// fallback to thread id
	return (idx_t)std::hash<std::thread::id>()(std::this_thread::get_id());
#endif
#endif
}

To Reproduce

Build with

make CMAKE_VARS=-DDISABLE_THREADS=1

The build fails with error

In file included from src/parallel/ub_duckdb_parallel.cpp:16:
src/parallel/task_scheduler.cpp: In static member function ‘static duckdb::idx_t duckdb::TaskScheduler::GetEstimatedCPUId()’:
src/parallel/task_scheduler.cpp:339:46: error: ‘thread’ is not a member of ‘std’
  339 |                 return (idx_t)std::hash<std::thread::id>()(std::this_thread::get_id());
      |                                              ^~~~~~
src/parallel/task_scheduler.cpp:24:1: note: ‘std::thread’ is defined in header ‘<thread>’; this is probably fixable by adding ‘#include <thread>’
   23 | #include <unistd.h>
  +++ |+#include <thread>
   24 | #endif
src/parallel/task_scheduler.cpp:339:46: error: ‘thread’ is not a member of ‘std’
  339 |                 return (idx_t)std::hash<std::thread::id>()(std::this_thread::get_id());
      |                                              ^~~~~~
src/parallel/task_scheduler.cpp:339:46: note: ‘std::thread’ is defined in header ‘<thread>’; this is probably fixable by adding ‘#include <thread>’
src/parallel/task_scheduler.cpp:339:56: error: template argument 1 is invalid
  339 |                 return (idx_t)std::hash<std::thread::id>()(std::this_thread::get_id());
      |                                                        ^
src/parallel/task_scheduler.cpp:339:65: error: ‘std::this_thread’ has not been declared
  339 |                 return (idx_t)std::hash<std::thread::id>()(std::this_thread::get_id());
      |                                                                 ^~~~~~~~~~~

OS:

Ubuntu 24.04

DuckDB Version:

latest source on main branch

DuckDB Client:

duckdb

Hardware:

No response

Full Name:

Zartaj Majeed

Affiliation:

NA

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a source build

Did you include all relevant data sets for reproducing the issue?

Yes

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

  • Yes, I have

Metadata

Metadata

Assignees

No one assigned

    Labels

    PR submittedA pull request was submitted to fix the issuereproduced

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions