Home Bug Reports

FreeBSD compilation problem: pthread_t is not unsigned long

Hi,

I've got almost all of ICE compiled under FreeBSD-CURRENT.

I've encountered one problem though:

gmake[2]: Entering directory `/usr/home/rodrigc/ice/Ice-1.0.0/src/IceSSL'
c++ -c -I.. -I../../include -I/usr/local/include -g -ftemplate-depth-128 -fPI
C -Wall OpenSSLPluginI.cpp
OpenSSLPluginI.cpp: In function `long unsigned int IceSSL::idFunction()':
OpenSSLPluginI.cpp:151: invalid conversion from `pthread*' to `long unsigned
int'
gmake[2]: *** [OpenSSLPluginI.o] Error 1


The problem is caused by this code in OpenSSLPluginI.cpp:

unsigned long IceSSL::idFunction()
{
unsigned long threadID = 0;

#ifdef WINDOWS
threadID = GetCurrentThreadId();
#elif _POSIX_THREADS
threadID = pthread_self();
#else
#error You must define a method to return the current thread ID.
#endif

return threadID;
}



This code is taking advantage of a Linux-ism, where threads are actually
processes, and a pthread_t == pid_t. Unfortunately, pthread_t should
be treated as an opaque type, and should not be assumed to be an
an unsigned long. On FreeBSD, pthread_t is a typedef for
a pointer to struct pthread. struct pthread is a FreeBSD specific data structure.

My short term compilation fix is to do:

threadID = (unsigned long)pthread_self();

But this seems wrong....ie. this amounts to casting a pointer to a long,
which makes me shudder.

What is the intent of this code?

Thanks.

Comments

  • marlowamarlowa Member Andrew MarlowOrganization: Wellabove LtdProject: study into feasibility of ice on WINCE project ✭✭
    Re: FreeBSD compilation problem: pthread_t is not unsigned long
    Originally posted by rodrigc
    Hi,

    The problem is caused by this code in OpenSSLPluginI.cpp:

    unsigned long IceSSL::idFunction()
    {
    unsigned long threadID = 0;

    #ifdef WINDOWS
    threadID = GetCurrentThreadId();
    #elif _POSIX_THREADS
    threadID = pthread_self();
    #else
    #error You must define a method to return the current thread ID.
    #endif

    return threadID;
    }

    This code is taking advantage of a Linux-ism,

    It is not a Linux-ism, the actual type of a thread id is implementation-dependent. So the above happens to work on Linux and Solaris but you have found that it doesn't work on openBSD. I know that the assumption also fails on HPUX.

    Regards,

    Andrew M.
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    Unfortunately, there is not much we can do about this. OpenSSL assumes that a thread id can be mapped to an unsigned long:

    void CRYPTO_set_id_callback(unsigned long (*id_function)(void));

    See: http://www.openssl.org/docs/crypto/threads.html
Sign In or Register to comment.