[Python-Dev] pthreads question: typedef ??? pthread_t and hacky return statements (original) (raw)
Mark Favas m.favas@per.dem.csiro.au
Thu, 17 Aug 2000 12:27:20 +0800
- Previous message: [Python-Dev] Re: os.path.commonprefix breakage
- Next message: [Python-Dev] timeout support for socket.py? (was: [ANN] TCP socket timeout module --> timeoutsocket.py)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Trent} -------------- 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;
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?
This is a DEC-threads thing... (and I'm not a DEC-threads savant). Making the suggested change gives the compiler warning:
cc -O -Olimit 1500 -I./../Include -I.. -DHAVE_CONFIG_H -c thread.c -o thread.o cc: Warning: thread_pthread.h, line 182: In this statement, "threadid" of type " pointer to struct __pthread_t", is being converted to "long". (cvtdiftypes) return threadid; ---------------^
The threads test still passes with this change.
From the pthread.h file,
typedef struct __pthreadTeb_t { __pthreadLongAddr_p _Pfield(reserved1); /* Reserved to DECthreads / __pthreadLongAddr_p _Pfield(reserved2); / Reserved to DECthreads / unsigned short _Pfield(size); / V1: Size of TEB / unsigned char _Pfield(version); / TEB version / unsigned char _Pfield(reserved3); / Reserved to DECthreads / unsigned char _Pfield(external); / V1: PTHREAD_TEB_EFLG_ flgs / unsigned char _Pfield(reserved4)[2]; / RESERVED / unsigned char _Pfield(creator); / V1: PTHREAD_TEB_CREATOR_* / __pthreadLongUint_t _Pfield(sequence); / V0: Thread sequence / __pthreadLongUint_t _Pfield(reserved5)[2]; / Reserved to DECthreads / __pthreadLongAddr_t _Pfield(per_kt_area); / V0: Reserved / __pthreadLongAddr_t _Pfield(stack_base); / V0: Initial SP / __pthreadLongAddr_t _Pfield(stack_reserve); / V0: reserved stack / __pthreadLongAddr_t _Pfield(stack_yellow); / V0: yellow zone / __pthreadLongAddr_t _Pfield(stack_guard); / V0: guard (red) zone / __pthreadLongUint_t _Pfield(stack_size); / V0: total stack size / __pthreadTsd_t _Pfield(tsd_values); / V0: TSD array (void *) / unsigned long _Pfield(tsd_count); / V0: TSD array size / unsigned int _Pfield(reserved6); / Reserved to DECthreads / unsigned int _Pfield(reserved7); / Reserved to DECthreads / unsigned int _Pfield(thread_flags); / Reserved to DECthreads / int _Pfield(thd_errno); / V1: thread's errno / __pthreadLongAddr_t _Pfield(stack_hiwater); / V1: lowest known SP */ } pthreadTeb_t, *pthreadTeb_p;
if defined (PTHREAD_ALLOW_MIXED_PROTOS) && defined
(__INITIAL_POINTER_SIZE) typedef pthreadTeb_p pthread_t; /* Long pointer if possible */
pragma __required_pointer_size __restore
elif defined (_PTHREAD_ENV_ALPHA) && defined (_PTHREAD_ENV_VMS)
typedef unsigned __int64 pthread_t; /* Force 64 bits anyway */
else
typedef pthreadTeb_p pthread_t; /* Pointers is pointers */
endif
#endif
-- Mark
- Previous message: [Python-Dev] Re: os.path.commonprefix breakage
- Next message: [Python-Dev] timeout support for socket.py? (was: [ANN] TCP socket timeout module --> timeoutsocket.py)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]