i have a basic question to the pthread_t variable.
what are valid values for the pthread_t variable after call to function
pthread_create?
eg.
static void* threadfunc (void *pv)
{
return 0;
}
pthread_t tid;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
pthread_attr_setstacksize(&attr, PTHREAD_STACKSIZE);
pthread_create(&tid, &attr, threadfunc, 0);
is it possible that 0 is a valid threadhandle?
thx in advance for your info...
markus
This is a meaningless question. The pthread_t variable is an opaque
type. There are no valid or invalid values, it simply has whatever value
it has.
> is it possible that 0 is a valid threadhandle?
No, because '0' is an integer, not a pthread_t. Valid thread handles
must be pthread_t's. You could never compare a thread handle to zero
because to do that, you'd either have to cast the zero to a pthread_t or
the pthread_t to an integer class. Neither conversion is allowed.
DS
"David Schwartz" <dav...@webmaster.com> schrieb im Newsbeitrag
news:3B855298...@webmaster.com...
> i´ve got a unixware 7.1.1 system with gnu 2.95.2pl1 compiler.
> in the headerfile types.h pthread_t is a typedef of long so set it to an
> integer value is possible, am i right?
Not according to the pthreads standard. Are you trying to follow the
standard or not?
Did you know that you can't even compare two pthread_t's with '==' or
'!='. The function pthread_equal exists for that purpose.
DS
You are right. But only today, only using unixware 7.1.1
with the gnu 2.95.2pl1 compiler, and only using the libraries
and header files on your system right this moment. Move to a
different system, move to a different compiler, update to a
newer compiler, apply a patch to the libraries -- and all bets
are off.
Every pthreads implementation must provide a pthread_t.
Like any other data type, a pthread_t must ultimately be made
up of some assemblage of "native" types, so it is no surprise
that if you study your own implementation's version of pthread_t
you find it's made of familiar components. But exactly the
same could be said of the FILE data type provided by <stdio.h>,
and (I presume) you're not foolish enough to believe that the
FILE in your <stdio.h> looks the same as that in some other
implementation's <stdio.h>. It's the same with pthread_t:
every implementation must use some kind of a "native" type,
but different implementations will choose different underlying
types (for their own reasons).
In at least one pthreads implementation, pthread_t is a
struct with three elements, so an attempt to assign zero to
a pthread_t or to compare a pthread_t to zero would generate
errors at compile time.
thx for your opinion!
"Eric Sosman" <Eric....@sun.com> schrieb im Newsbeitrag
news:3B8565C0...@sun.com...
> Markus Fischbacher wrote:
> >
> > i´ve got a unixware 7.1.1 system with gnu 2.95.2pl1 compiler.