Open kingtaurus opened 9 years ago
Issue https://github.com/ValveSoftware/vogl/issues/197 also includes solutions. Apologies for duplicating.
So, pthread_self()
returns pthread_t
(according to pthread_self specification). So I'm confused as to why the reinterpret_cast<>
is required.
pthread_t is an abstract type. It can be, quite literally, anything. EDIT: Well, for what it's worth, I'd say it's healthier for the long term to avoid the reinterpret cast in this case. Some minor design changes can fix the issue but I'm not really sure what would be a desirable way to go about it without some insight.
Well the options are to avoid the cast altogether:
(1) both 32-bit and 64-bit linux define a pthread_t
through the following typedef:
typedef unsigned long int pthread_t;
See /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h
and /usr/include/i386-linux-gnu/bits/pthreadtypes.h
; which should convert directly to uint64_t
without issue.
This would require OS X specific code to handle the pthread_t
(and its associated pthread_t definition). _pthread_types.h , pthread.h
typedef __darwin_pthread_t pthread_t;
and
typedef struct _opaque_pthread_t
*__darwin_pthread_t; /* [???] Used for pthreads */
finally,
struct _opaque_pthread_t {
long __sig;
struct __darwin_pthread_handler_rec *__cleanup_stack;
char __opaque[__PTHREAD_SIZE__];
};
where
#if defined(__LP64__)
#define __PTHREAD_SIZE__ 8176
//...
#else // !__LP64__
#define __PTHREAD_SIZE__ 4088
//...
#endif
and
struct __darwin_pthread_handler_rec {
void (*__routine)(void *); // Routine to call
void *__arg; // Argument to pass
struct __darwin_pthread_handler_rec *__next;
};
Although this information is really recent, it appears that the storage class is a signed long
(so, unpacking this from the pthread_t would convert directly to uint64_t
easily). Further the reinterpret_cast<>
just converts the address of _opaque_pthread_t
that is allocated on the heap and not the actual pthread_t
id (which most likely is a bug).
(2) Move to C++11 (or boost::thread)and use std::thread
, std::mutex
, and what not. This would probably require a re-write within the core libraries (and a lot more testing).
I'm trying to build vogl on an i686 Ubuntu 14.04 machine
So, pulling from
vogl/master
(making sure I'm up to date):Build Error:
This issue arises because (/usr/include/stdint.h):
Now pthread_t (/usr/include/i386-linux-gnu/bits/pthreadtypes.h):
I believe that
unsigned long int
in this case is the same type asunsigned int
(i386) - thus the reinterpret_cast<> is invalid. I can write up a simple fix (just surprised that no one else has stumbled on this) - however I feel that I should report this first.Edit: improved formatting and fixed a few small mistakes