std::thread error

Jeff Webb jeff.webb at nta-inc.net
Tue Sep 29 19:48:41 UTC 2015


On 09/29/2015 11:04 AM, Jeff Webb wrote:
> On 09/29/2015 12:51 AM, Sebastian Huber wrote:
>>
>>
>> On 28/09/15 23:52, Jeff Webb wrote:
>>> To me, it looks like this:
>>>
>>> libgcov-interface.c includes gthr.h
>>> gthr.h includes gthr-default.h.
>>> gthr-default.h includes pthread.h
>>> newlib/libc/include/pthread.h is found first, which does not include sched.h
>>> after including pthread.h, gthr-default.h tries to reference sched_yield
>>>   i.e.: "__gthrw(sched_yield)"
>>> gthr-default.h then includes sched.h later in the file.
>>> sched.h defines sched_yield, but it is too late.
>>>
>>> Of course, I could easily be confused.
>>
>> The --enable-threads=posix is largely untested. I never used it myself. There is a probably a bug in the Newlib <pthread.h>, see also
>>
>>   http://pubs.opengroup.org/onlinepubs/007908799/xsh/pthread.h.html
>>
>> "Inclusion of the <pthread.h> header will make visible symbols defined in the headers <sched.h> and <time.h>."
>>
>
> Thanks for the pointer.  I have made some progress.  With the following change to newlib-cygwin.git, I was able to use the source builder to build the 4.11/rtems-arm tool suite with --enable-threads=posix.
>
> $ git diff
> diff --git a/newlib/libc/include/pthread.h b/newlib/libc/include/pthread.h
> index db1f9c1..a5733d5 100644
> --- a/newlib/libc/include/pthread.h
> +++ b/newlib/libc/include/pthread.h
> @@ -30,6 +30,7 @@ extern "C" {
>   #if defined(_POSIX_THREADS)
>
>   #include <sys/types.h>
> +#include <sched.h>
>   #include <time.h>
>   #include <sys/sched.h>
>   #include <sys/cdefs.h>
>
> I was then able to successfully rebuild RTEMS for the zedboard as I did before.  I was also able to compile and run the POSIX examples in examples-v2, as before.
>
> When compiling my own C++ test application I also discovered another issue in:
>
> /opt/rtems/compiler/4.11/arm-rtems4.11/include/pthread.h
>
> It looks like a const is omitted, when compared to my linux version:
>
> int     _EXFUN(pthread_setschedparam,
>          (pthread_t __pthread, int __policy, struct sched_param *__param));
>
> The POSIX spec Sebastian referenced above seems to indicate that we need a const:
>
> int   pthread_setschedparam(pthread_t, int, const struct sched_param *);
>
> After removing consts from my C++ code, I was able to get my sample application to compile.  However, when I run it, I get this error message:
>
> terminate called after throwing an instance of 'std::system_error'
>    what():  Enable multithreading to use std::thread: Not owner
>
> Now I'm trying to track down the source of this error.  Any ideas?
  
The following change to the gcc-4.9.3 source tree fixed the error above, and I was able to run a test program that uses std::thread.

diff -ur a/libgcc/gthr-posix.h b/libgcc/gthr-posix.h
--- a/libgcc/gthr-posix.h       2014-01-02 16:25:22.000000000 -0600
+++ b/libgcc/gthr-posix.h       2015-09-29 13:42:07.143099538 -0500
@@ -246,9 +246,12 @@
  static inline int
  __gthread_active_p (void)
  {
+    return 1;
+/*
    static void *const __gthread_active_ptr
      = __extension__ (void *) &GTHR_ACTIVE_PROXY;
    return __gthread_active_ptr != 0;
+*/
  }
  
  #endif /* FreeBSD or Solaris */



More information about the users mailing list