Boost logo

Boost :

From: Ryan, Paul L. (PAUL.L.RYAN_at_[hidden])
Date: 2006-07-10 13:31:50


Ion,
 
The named semaphore on linux seems to never increment the initial count when
creating. Looking into the posix implementation a sem_init is never called
if create is given and it just returns true.
 
      bool operator()(const shared_memory::segment_info_t * info, bool
created) const
      {
         mp_sem = reinterpret_cast<sem_t *>(info->get_user_ptr());
         switch(m_create){
            case open_only:
               mp_sem = reinterpret_cast<sem_t *>(info->get_user_ptr());
            break;
 
            case open_or_create:
               if(created){
                  if(sem_init(mp_sem, 1, m_initialCount) == 0){
                     return true;
                  }
                  else{
                     mp_sem = 0;
                     return false;
                  }
               }
            break;
 
            case create_only:
               return true;
            break;
         
            default:
               return false;
            break;
         }
         return true;
      }
 
I think this method should be
 
      bool operator()(const shared_memory::segment_info_t * info, bool
created) const
      {
         mp_sem = reinterpret_cast<sem_t *>(info->get_user_ptr());
         switch(m_create){
            case open_only:
               mp_sem = reinterpret_cast<sem_t *>(info->get_user_ptr());
            break;
 
            case open_or_create:
               if(created){
                  if(sem_init(mp_sem, 1, m_initialCount) == 0){
                     return true;
                  }
                  else{
                     mp_sem = 0;
                     return false;
                  }
               }
            break;
 
            case create_only:
                  if(sem_init(mp_sem, 1, m_initialCount) == 0){
                     return true;
                  }
                  else{
                     mp_sem = 0;
                     return false;
                  }
            break;
         
            default:
               return false;
            break;
         }
         return true;
      }
 
Paul Ryan
SAIC - Tactical Systems
 


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk