2

i am working with boost::mutex class to synchronize 2 threads on one resource. i get an exception when i call the following boost:mutex:lock() function:

lock()
{
   int const res=pthread_mutex_lock(&m);
   if(res)
   {
      boost::throw_exception(lock_error(res));
   }
}

res = 22 which is EINVAL. when i look at the man page of pthread_mutex_lock i can see that the function will not EINVAL in the following cases:

EINVAL: The value specified by mutex does not refer to an initialized mutex object.

this option is not relevant since boost:mutex constructor initializes the pthread_mutex_t.

EINVAL: The mutex was created with the protocol attribute having the value PTHREAD_PRIO_PROTECT and the calling thread's priority is higher than the mutex's current priority ceiling.

this option is much more reasonable. when you look at the initialization of the pthread_mutex_t in the boost::mutex custructor you see:

mutex()
 {
   int const res=pthread_mutex_init(&m,NULL);
   if(res)
   {
       boost::throw_exception(thread_resource_error());
   }
 }

that means that boost use the default pthread_mutexattr_t for the mutex. my question is:

  1. does the default value of the pthread_mutexattr_t includes protocol attribute having the value PTHREAD_PRIO_PROTECT ?

  2. if you, my problem gets worst, since i depend on the thread priority that tries to lock the mutex. my thread is created by ACE_Task_Base::activate. can you tell me what is the ace default thread priority ?

i am running on linux redhat...

Oded
  • 664
  • 2
  • 9
  • 30

0 Answers0