title: boost::interprocess sync mechanisms (mutex, condition) in shared memory between 32 & 64 bit programs on OSX
body: <p>OSX 10.11.6, boost 1.63.0</p>
  
  <p>I have a 64 bit <strong>master</strong> process that is using a 32 bit <strong>slave</strong> process to do some realtime rendering (I don't have the source code to a particular 32 bit dynamic library so I can't recompile it as 64 bit). Timing is critical and I've found the shared memory utilities of boost::interprocess to work very well, but I've run into interoperability issues. Some of the interprocess mechanisms are different sizes when compiled 32 vs 64 &amp; thus cause issues when the <strong>slave</strong> references them from the shared memory.</p>
  
  <pre><code>64 bit
  Scoped Lock: 16
  Condition: 48
  Mutex: 64
  Semaphore: 4
  
  32 bit
  Scoped Lock: 8
  Condition: 28
  Mutex: 44
  Semaphore: 4
  </code></pre>
  
  <p>I dug down into the boost::interprocess::interprocess_mutex header and found the sizes declared in <strong>_pthread_types.h</strong>:</p>
  
  <pre><code>// pthread opaque structures
  #if defined(__LP64__)
  #define __PTHREAD_SIZE__        8176
  #define __PTHREAD_ATTR_SIZE__       56
  #define __PTHREAD_MUTEXATTR_SIZE__  8
  #define __PTHREAD_MUTEX_SIZE__      56
  #define __PTHREAD_CONDATTR_SIZE__   8
  #define __PTHREAD_COND_SIZE__       40
  #define __PTHREAD_ONCE_SIZE__       8
  #define __PTHREAD_RWLOCK_SIZE__     192
  #define __PTHREAD_RWLOCKATTR_SIZE__ 16
  #else // !__LP64__
  #define __PTHREAD_SIZE__        4088
  #define __PTHREAD_ATTR_SIZE__       36
  #define __PTHREAD_MUTEXATTR_SIZE__  8
  #define __PTHREAD_MUTEX_SIZE__      40
  #define __PTHREAD_CONDATTR_SIZE__   4
  #define __PTHREAD_COND_SIZE__       24
  #define __PTHREAD_ONCE_SIZE__       4
  #define __PTHREAD_RWLOCK_SIZE__     124
  #define __PTHREAD_RWLOCKATTR_SIZE__ 12
  #endif // !__LP64__
  
  struct _opaque_pthread_mutex_t {
      long __sig;
      char __opaque[__PTHREAD_MUTEX_SIZE__];
  };
  </code></pre>
  
  <p>When using</p>
  
  <pre><code>boost::interprocess::interprocess_mutex
  boost::interprocess::interprocess_condition
  </code></pre>
  
  <p>with both programs compiled as 64 bit, the data rendering works extremely well.</p>
  
  <p>Is there any way to force size conformity? Or perhaps there's a different IPC mechanism I'm overlooking?</p>
  
  <p>The great thing about using conditions is that they can signal the blocked thread when to wake and greatly minimize wasted CPU cycles, since the waiting thread/process doesn't have to be constantly running to check a value. Is there another way to signal threads/processes in this manner?</p>
  
  <p>I know of at least a couple programs on OSX that have implemented highly fast and efficient data rendering between 64 bit &lt;-> 32 bit so the answer's gotta be out there somewhere..</p>