[Python-Dev] pthreads question: typedef ??? pthread_t and hacky return statements

Vladimir Marangozov Vladimir.Marangozov@inrialpes.fr
Thu, 17 Aug 2000 03:41:48 +0200 (CEST)


Trent Mick wrote:
> 
> I am porting Python to Monterey (64-bit AIX) and have a small (hopefully)
> question about POSIX threads. I have Monterey building and passing the
> threads test suite using Python/thread_pthread.h with just one issue:
> 
> -------------- snipped from current thread_pthread.h ---------------
> long
> PyThread_get_thread_ident(void)
> {
>     volatile pthread_t threadid;
>     if (!initialized)
>         PyThread_init_thread();
>     /* Jump through some hoops for Alpha OSF/1 */
>     threadid = pthread_self();
>     return (long) *(long *) &threadid;
> }
> -------------------------------------------------------------------
> 
> ...
> 
> WHAT IS UP WITH THAT return STATEMENT?
>   return (long) *(long *) &threadid;

I don't know and I had the same question at the time when there was some
obscure bug on my AIX combo at this location. I remember that I had played
with the debugger and the only workaround at the time which solved the
mystery was to add the 'volatile' qualifier. So if you're asking yourself
what that 'volatile' is for, you have one question less...

> 
> My *guess* is that this is an attempt to just cast 'threadid' (a pthread_t)
> to a long and go through hoops to avoid compiler warnings. I dont' know what
> else it could be. Is that what the "Alpha OSF/1" comment is about? Anybody
> have an Alpha OSF/1 hanging around. The problem is that when
> sizeof(pthread_t) != sizeof(long) this line is just broken.
> 
> Could this be changed to
>   return threadid;
> safely?

I have the same question. If Guido can't answer this straight, we need
to dig the CVS logs.

-- 
       Vladimir MARANGOZOV          | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252