Menu

#494 Make plugins/ipmidirect/thread.cpp more portable

2.10.2
closed-fixed
5
2008-01-28
2007-09-07
No

The initialization of pthread synchonization objects in plugins/ipmidirect/thread.cpp should be more portable.

The following code fragments from thread.cpp show the initialization of pthread synchronization objects by copying a static object:

...
static pthread_mutex_t lock_tmpl = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;

cThreadLock::cThreadLock()
m_lock( lock_tmpl )
{
}
...
static pthread_rwlock_t rwlock_tmpl = PTHREAD_RWLOCK_INITIALIZER;

cThreadLockRw::cThreadLockRw()
{
m_rwlock = rwlock_tmpl;
}
...
static pthread_cond_t cond_tmpl = PTHREAD_COND_INITIALIZER;

cThreadCond::cThreadCond()
{
m_cond = cond_tmpl;
}

The use of pthread synchronization objects initialized in this way is not defined by POSIX. See the comments in the description sections of the following:

http://www.opengroup.org/onlinepubs/000095399/functions/pthread_mutex_init.html
http://www.opengroup.org/onlinepubs/000095399/functions/pthread_rwlock_init.html
http://www.opengroup.org/onlinepubs/000095399/functions/pthread_cond_init.html

Also see the following thread from the comp.programming.threads news group:

http://groups.google.com/group/comp.programming.threads/browse_thread/thread/69bfbe69b2f801f/d8aa921878e621ac?lnk=gst&q=mutex+assignment

I have attached a patch which calls pthread initialization functions instead of using the code above. The patch doesn't include error handling code. The initialization functions are called in constructors. Exceptions could be thrown if these initialization functions fail. However, exceptions are not used in the other plugin code, and I was unsure if exceptions would be the preferred approach.

Discussion

  • Chris Rinaldo

    Chris Rinaldo - 2007-09-07

    Patch to make plugins/ipmidirect/thread.cpp more portable

     
  • Chris Rinaldo

    Chris Rinaldo - 2008-01-09

    Logged In: YES
    user_id=1877074
    Originator: YES

    I have attached an alternative patch, solaris-thread.cpp.patch. This patch uses ifdefs so that the pthread synchronization objects are dynamically initialized on Solaris. This allows thread.cpp to compile on Solaris without changing the current initialization scheme for synchronization objects on other systems.

    File Added: solaris-thread.cpp.patch

     
  • Chris Rinaldo

    Chris Rinaldo - 2008-01-09

    An alternative patch to thread.ccp for Solaris

     
  • Pierre Sangouard

    Logged In: YES
    user_id=944149
    Originator: NO

    Solaris patch applied to trunk (rev 6634)

     
  • Pierre Sangouard

    • milestone: --> 761454
    • status: open --> closed-fixed
     
  • Pierre Sangouard

    • milestone: 761454 --> 2.10.2
     
  • Pierre Sangouard

    Logged In: YES
    user_id=944149
    Originator: NO

    Patch applied to branch 2.10.x (rev 6654)

     

Log in to post a comment.

MongoDB Logo MongoDB