Web lists-archives.com

Re: [Mingw-users] GCC-4.9.3 is now our current release

Hello Ralph!

On Tue, Mar 15, 2016 at 12:57 PM, ralph engels <ralphengels@xxxxxxxxx> wrote:
> Needed some changes but i can report that gcc now builds with
> pthreads-w32 again.
> Three things that needed changes.
> ...
> pthread_t is cast from a struct but gcc expects it to be of scalar
> integer type, again restrict to build time and cast pthread_t to
> unsigned int for release (should be uintptr_t but since this patch is
> against a strictly 32 bit compiler i left it at that).

Disclaimer: I am looking at code from about five years ago and I
haven't looked at you patch, so my comments might not be relevant.

Based on old (about five years ago) pthreads-win32 and mingw gcc
4.6, I see a problem with your approach, and I'm surprised it works.

pthread_t maps (is typedef'ed) to ptw32_handle_t which is a struct:

   typedef struct {
       void * p;                   /* Pointer to actual object */
       unsigned int x;             /* Extra information - reuse count etc */
   } ptw32_handle_t;

gcc's threading model uses a "gthread" abstraction layer that is very
similar to pthreads and follows, as you noted, the standard linux
approach (not technically consistent with posix, but the de facto
standard) of having __gthread_t be pthread_t, which is assumed to
be a scalar type (in fact a pointer).

I just don't see how you can cast from ptw32_handle_t (a two-member
struct) to an unsigned int, and not break all kinds of stuff.

I do see member x being used in the pthreads code (so it's not just
"dead" data), e.g., in pthread_equal:

   pthread_equal (pthread_t t1, pthread_t t2)
     int result;
     result = ( t1.p == t2.p && t1.x == t2.x );
     return (result);

So unless the guts of gthread and pthreads-win32 have changed
a lot since I last looked at it, your cast-pthread_t-to-unsigned-int
work-around looks really risky.

> ...
> I have sent a patch to Keith with my changes.
> ...

Happy Multi-Threaded Hacking!

K. Frank

Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
MinGW-users mailing list

This list observes the Etiquette found at 
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

You may change your MinGW Account Options or unsubscribe at:
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe