Reputation: 22946
From: https://www.sourceware.org/pthreads-win32/manual/pthread_mutex_init.html
Variables of type pthread_mutex_t can also be initialized statically,
So, what is the type of pthread_mutex_t?
Upvotes: 5
Views: 46584
Reputation: 1567
From pthreadtypes.h, in my Linux distribution its definition is pretty clear as a typedef for a union, as defined below:
/* Data structures for mutex handling. The structure of the attribute
type is not exposed on purpose. */
typedef union
{
struct __pthread_mutex_s
{
int __lock;
unsigned int __count;
int __owner;
/* KIND must stay at this position in the structure to maintain
binary compatibility. */
int __kind;
unsigned int __nusers;
__extension__ union
{
int __spins;
__pthread_slist_t __list;
};
} __data;
char __size[__SIZEOF_PTHREAD_MUTEX_T];
long int __align;
} pthread_mutex_t;
You'll want to use it as their defined type, pthread_mutex_t of course -- since this type will vary by OS / distribution / etc.
Upvotes: 13
Reputation: 4049
pthread_mutex_t
is a type, so it doesn't have a type itself. If you are curious about what this type is an alias for, on my machine I have:
struct _opaque_pthread_mutex_t {
long __sig;
char __opaque[__PTHREAD_MUTEX_SIZE__];
};
and then
typedef struct _opaque_pthread_mutex_t __darwin_pthread_mutex_t;
and finally:
typedef __darwin_pthread_mutex_t pthread_mutex_t;
Upvotes: 3
Reputation: 5277
That is the type. The implementation underneath is often a struct and you can look in the header files if you really care about the specific implementation of the library you're using, but those details don't matter for using it, you just care about the pthread_mutex_t
type.
pthread_mutex_t mymutex = PTHREAD_MUTEX_INITIALIZER;
Upvotes: 10