pthreads problem - SGI

This is a discussion on pthreads problem - SGI ; Hi I have a line at the top of a .cpp file: pthread_t mainThreadId = pthread_self(); later, from main(): result = pthread_equal( mainThreadId, pthread_self() ); this returns true on Linux (as I expected), but on IRIX 6.5 it returns false. ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: pthreads problem

  1. pthreads problem

    Hi

    I have a line at the top of a .cpp file:
    pthread_t mainThreadId = pthread_self();

    later, from main():
    result = pthread_equal( mainThreadId, pthread_self() );

    this returns true on Linux (as I expected), but on IRIX 6.5 it returns false. why?


    The code below illustrates the problem:

    #include
    #include

    pthread_t init = pthread_self();

    int main( int argv, char args[]) {

    printf( "Result is: %i \n", pthread_equal( pthread_self(), pthread_self() ) );
    printf( "Result is: %i \n", pthread_equal( pthread_self(), init ) );
    }


    When compiled with gcc on Linux, output is:
    Result is: 1
    Result is: 1

    When compiled with gcc on IRIX 6.5, output is:
    Result is: 1
    Result is: 0


    I'm pretty stumped...

    Also, why can't you use :thread_equal in IRIX? Yet :thread_self works ok?

  2. Re: pthreads problem

    On Mon, 27 Oct 2003, Steven Wong wrote:

    > I have a line at the top of a .cpp file:
    > pthread_t mainThreadId = pthread_self();
    >
    > later, from main():
    > result = pthread_equal( mainThreadId, pthread_self() );
    >
    > this returns true on Linux (as I expected), but on IRIX 6.5 it returns false. why?


    I tried your test code on 6.5.22 and 6.5.21 with MIPSpro 7.4 and 7.2.1.3m,
    and g++ 3.3 (from Freeware). I even tried omitting "-lpthread" on the
    compile line. I could not reproduce the problem (i.e. the result was
    always 1). It seems more information is necessary (i.e. exact OS release
    [uname -aR], compiler version, etc).

    > Also, why can't you use :thread_equal in IRIX? Yet :thread_self works ok?


    I don't claim to know much about C++ scoping rules, so I'll leave this
    to others to answer.

    Brent Casavant

    --
    Brent Casavant bcasavan@sgi.com Forget bright-eyed and
    Operating System Engineer http://www.sgi.com/ bushy-tailed; I'm red-
    Silicon Graphics, Inc. 44.8562N 93.1355W 860F eyed and bushy-haired.

  3. Re: pthreads problem

    In article ,
    Steven Wong wrote:
    [ nice test case removed. I also tried it and got
    Result is: 1
    Result is: 1
    consistently
    ]
    >Also, why can't you use :thread_equal in IRIX? Yet :thread_self works ok?


    pthread_equal is a macro and a function.
    But :: on the macro makes no sense.
    See /usr/include/pthread.h
    int pthread_equal(pthread_t, pthread_t);
    #define pthread_equal(t1, t2) ((t1) == (t2))



    http://www.unix-systems.org/single_unix_specification/
    speaks of pthread_equal as a function, not a macro.

    But that same spec says on the pthread.h page:
    "The following shall be declared as functions and
    may also be defined as macros. Function prototypes shall be provided. "
    and pthread_equal is on that list.



    So any portable app that wishes to use :thread_equal must use
    #undef pthread_equal
    after #include

    Indeed pthread_self() could also be a macro, so a portable app
    would need to do
    #undef pthread_self
    to use :thread_self() safely.


    So: no bug in IRIX here, AFAICT.

    Regards,
    David B. Anderson davea@sgi.com http://reality.sgiweb.org/davea

  4. Re: pthreads problem

    I'm compiling on a Tezro, with IRIX 6.5.21f and CC version 7.41.
    I think I might have figured out the problem.

    compiling with:
    cc test.C -lpthread

    gives the 0 result,

    but compiling with:
    CC test.C -lpthread
    gives the 1 result.

    I'm not sure why this is, and in our actual program, CC is being used
    to compile. I guess that means the problem must be elsewhere in the
    program's code.
    I'll keep looking.


    As for the :thread_equals, I took a look at that link, and it seems
    like pretty much all of the pthread_* functions can be defined as
    macros. So would it be simpler to just use pthread_* when calling
    pthread functions and leave off the ::?


    thanks for the help!

+ Reply to Thread