[PATCH] Fix --disable-threading build
Pedro Alves
pedro@palves.net
Tue May 10 13:54:44 GMT 2022
On 2022-05-09 19:08, Tom Tromey via Gdb-patches wrote:
> PR build/29110 points out that GDB fails to build on mingw when the
> "win32" thread model is in use. It turns out that the Fedora cross
> tools using the "posix" thread model, which somehow manages to support
> std::future, whereas the win32 model does not.
I guess it depends on GCC version. Ubuntu 20.04 ships both win32 and posix
models as alternatives:
"
$ sudo update-alternatives --config x86_64-w64-mingw32-gcc
There are 2 choices for the alternative x86_64-w64-mingw32-gcc (providing /usr/bin/x86_64-w64-mingw32-gcc).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/x86_64-w64-mingw32-gcc-win32 60 auto mode
* 1 /usr/bin/x86_64-w64-mingw32-gcc-posix 30 manual mode
2 /usr/bin/x86_64-w64-mingw32-gcc-win32 60 manual mode
Press <enter> to keep the current choice[*], or type selection number:
"
and there the posix model doesn't have std::future either. The version is:
gcc version 9.3-posix 20200320 (GCC)
Above I have posix selected, but the default is win32.
>
> While looking into this, I found that the configuring with
> --disable-threading will also cause a build failure.
>
> This patch fixes this build by introducing a compatibility wrapper for
> std::future.
>
> I am not able to test the win32 thread model build, but I'm going to
> ask the reporter to try this patch.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29110
I tested this on Ubuntu 20.04, two builds, one with posix model, and another
with win32 model. Both worked (as in, gdb built).
> thread_pool::thread_function ()
> {
> diff --git a/gdbsupport/thread-pool.h b/gdbsupport/thread-pool.h
> index 5e203fd896c..fc35d61faf0 100644
> --- a/gdbsupport/thread-pool.h
> +++ b/gdbsupport/thread-pool.h
> @@ -27,13 +27,69 @@
> #include <thread>
> #include <mutex>
> #include <condition_variable>
> -#endif
> #include <future>
> +#endif
> #include "gdbsupport/gdb_optional.h"
>
> namespace gdb
> {
>
> +#if CXX_STD_THREAD
> +
> +/* Simply use the standard future. */
> +template<typename T>
> +using future = std::future<T>;
> +
> +#else /* CXX_STD_THREAD */
> +
> +/* A compatibility wrapper for std::future. Once <thread> and
> + <future> are available in all GCC builds -- should that ever happen
> + -- this can be removed.
I think this should mention mingw.
Otherwise LGTM.
Thanks for fixing this.
Pedro Alves
> +
> + Meanwhile, in this mode, there are no threads. Tasks submitted to
> + the thread pool are invoked immediately and their result is stored
> + here. The base template here simply wraps a T and provides some
> + std::future compatibility methods. The provided methods are chosen
> + based on what GDB needs presently. */
> +
> +template<typename T>
> +class future
More information about the Gdb-patches
mailing list