]> sourceware.org Git - valgrind.git/commitdiff
drd: Add support for C11 thrd_create()
authorBart Van Assche <bvanassche@acm.org>
Sun, 15 Oct 2023 14:36:33 +0000 (07:36 -0700)
committerBart Van Assche <bvanassche@acm.org>
Sun, 15 Oct 2023 15:32:04 +0000 (08:32 -0700)
NEWS
configure.ac
drd/drd_pthread_intercepts.c
drd/tests/Makefile.am
drd/tests/thrd_create.cpp [new file with mode: 0644]
drd/tests/thrd_create.stderr.exp [new file with mode: 0644]
drd/tests/thrd_create.vgtest [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index ad302827044a9c779ceba88c899f6a0fce890812..b2a385d8df983cc081cb25cda89dbc25682e5c77 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -86,6 +86,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 473870  FreeBSD 14 applications fail early at startup
 473944  Handle mold linker split RW PT_LOAD segments correctly
 474332  aligned_alloc under Valgrind returns nullptr when alignment is not a multiple of sizeof(void *)
+475650  DRD does not work with C11 threads
 n-i-bz  Allow arguments with spaces in .valgrindrc files
 n-i-bz  FreeBSD fixed reading of Valgrind tools own debuginfo
 
index d1b82c05d28fb23f2ec3047eae66d03e20d1a58c..95dbc702017b000d3ae1835be2b1e2845db9d04a 100755 (executable)
@@ -2080,6 +2080,26 @@ AC_LANG(C)
 
 AM_CONDITIONAL(CXX_CAN_INCLUDE_THREAD_HEADER, test x$ac_cxx_can_include_thread_header = xyes)
 
+AC_MSG_CHECKING([that the C++ compiler supports thrd_create()])
+AC_LANG(C++)
+safe_CXXFLAGS=$CXXFLAGS
+CXXFLAGS=-std=c++11
+
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
+#include <threads.h> 
+], [[thrd_t thr; return thrd_create(&thr, [](void *arg){return 0;}, NULL);]])],
+[
+ac_cxx_have_thrd_create=yes
+AC_MSG_RESULT([yes])
+], [
+ac_cxx_have_thrd_create=no
+AC_MSG_RESULT([no])
+])
+CXXFLAGS=$safe_CXXFLAGS
+AC_LANG(C)
+
+AM_CONDITIONAL(CXX_HAVE_THRD_CREATE, test x$ac_cxx_have_thrd_create = xyes)
+
 # Check whether compiler can process #include <condition_variable> without errors
 
 AC_MSG_CHECKING([that C++ compiler can include <condition_variable> header file])
index 1e6313e8ecaba5c64c23a7a9084b8f9595e29a87..b1b4762d633b9d4a1263c83392dce47342259ed1 100644 (file)
@@ -604,7 +604,8 @@ int pthread_create_intercept(pthread_t* thread, const pthread_attr_t* attr,
     * this means that the new thread will be started as a joinable thread.
     */
    thread_args.detachstate = PTHREAD_CREATE_JOINABLE;
-   if (attr)
+   /* The C11 thrd_create() implementation passes -1 as 'attr' argument. */
+   if (attr && (uintptr_t)attr + 1 != 0)
    {
       if (pthread_attr_getdetachstate(attr, &thread_args.detachstate) != 0)
          assert(0);
index 5482cf7be4309036ac404d5e7ebb3a548dcdd8e8..1b0beb4dae094f462123fdb1810f1e4e84843704 100755 (executable)
@@ -365,6 +365,8 @@ EXTRA_DIST =                                        \
        tc23_bogus_condwait.vgtest                  \
        tc24_nonzero_sem.stderr.exp                 \
        tc24_nonzero_sem.vgtest                     \
+       thrd_create.stderr.exp                      \
+       thrd_create.vgtest                          \
        thread_name.stderr.exp                      \
        thread_name.vgtest                          \
        thread_name_xml.stderr.exp                  \
@@ -513,6 +515,10 @@ if HAVE_SWAPCONTEXT
 check_PROGRAMS += swapcontext
 endif
 
+if CXX_HAVE_THRD_CREATE
+check_PROGRAMS += thrd_create
+endif
+
 if !VGCONF_OS_IS_DARWIN
 check_PROGRAMS += sem_wait
 endif
@@ -653,3 +659,5 @@ endif
 
 timed_mutex_SOURCES         = timed_mutex.cpp
 timed_mutex_CXXFLAGS        = $(AM_CXXFLAGS) -std=c++0x
+
+thrd_create_SOURCES        = thrd_create.cpp
diff --git a/drd/tests/thrd_create.cpp b/drd/tests/thrd_create.cpp
new file mode 100644 (file)
index 0000000..b0f3eee
--- /dev/null
@@ -0,0 +1,11 @@
+#include <threads.h>
+#include <iostream>
+
+int main()
+{
+  thrd_t thr;
+  thrd_create(&thr, [](void *arg){std::cerr << "Hello, world!\n"; return 0;},
+              NULL);
+  thrd_join(thr, NULL);
+  return 0;
+}
diff --git a/drd/tests/thrd_create.stderr.exp b/drd/tests/thrd_create.stderr.exp
new file mode 100644 (file)
index 0000000..f5fb437
--- /dev/null
@@ -0,0 +1,4 @@
+
+Hello, world!
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
diff --git a/drd/tests/thrd_create.vgtest b/drd/tests/thrd_create.vgtest
new file mode 100644 (file)
index 0000000..12b373e
--- /dev/null
@@ -0,0 +1,2 @@
+prereq: test -e thrd_create && ./supported_libpthread
+prog: thrd_create
This page took 0.046148 seconds and 5 git commands to generate.