Hi boost users,<div><br></div><div>I&#39;ve discovered that the following doesn&#39;t compile.</div><div><br></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� using namespace boost::interprocess;</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� interprocess_upgradable_mutex mutex;</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� interprocess_condition cv;</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� boost::posix_time::ptime deadline;</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div>
<font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� {</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� � �scoped_lock&lt;interprocess_upgradable_mutex&gt; lock(mutex);</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� � �sharable_lock&lt;interprocess_upgradable_mutex&gt; lock2(mutex);</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� � �cv.wait(lock); // doesn&#39;t compile</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� � �cv.timed_wait(lock, deadline); // doesn&#39;t compile.</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� }</font></div>
</div><div><br></div><div>It is failing because boost doesn&#39;t define the following methods:</div><div><br></div><div><div>�� <font class="Apple-style-span" face="&#39;courier new&#39;, monospace">void interprocess_condition::do_wait(interprocess_upgradable_mutex �&amp;mut);</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� bool�interprocess_condition::do_timed_wait(const syssrv_boost::posix_time::ptime &amp;abs_time, interprocess_upgradable_mutex &amp;mut);</font></div>
</div><div><br></div><div>I was thinking of making a basic implementation like so:</div><div><br></div><div>Define a <font class="Apple-style-span" face="&#39;courier new&#39;, monospace">scoped_unlock </font>class, which behaves just like <font class="Apple-style-span" face="&#39;courier new&#39;, monospace">scoped_lock</font> except the constructor unlocks and the destructor locks.</div>
<div><br></div><div>Then define the following:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">inline void interprocess_condition::do_wait(interprocess_upgradable_mutex &amp;mut)</font></div>
</div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">{</font></div></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� scoped_unlock&lt;interprocess_upgradable_mutex&gt; unlock(mut);</font></div>
</div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� interprocess_mutex &amp;internal_mutex = mut.m_mut;</font></div></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� scoped_lock&lt;interprocess_mutex&gt; internal_lock(internal_mutex);</font></div>
</div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� this-&gt;wait(internal_lock);</font></div></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">}</font></div>
</div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">inline bool interprocess_condition::do_timed_wait</font></div>
</div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� (const syssrv_boost::posix_time::ptime &amp;abs_time, interprocess_upgradable_mutex &amp;mut)</font></div></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">{</font></div>
</div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� scoped_unlock&lt;interprocess_upgradable_mutex&gt; unlock(mut);</font></div></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� interprocess_mutex &amp;internal_mutex = mut.m_mut;</font></div>
</div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� scoped_lock&lt;interprocess_mutex&gt; internal_lock(internal_mutex);</font></div></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">�� return this-&gt;timed_wait(internal_lock, abs_time);</font></div>
</div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">}</font></div></div></blockquote><div><br></div><div>These functions simply do the following:</div><div><ul><li>unlock the exclusive lock on the�<span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">interprocess_upgradable_mutex</span>�(which is emulated with an internal�<span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">interprocess_mutex</span>)</li>
<li>then lock the internal�<span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">interprocess_mutex</span></li><li>Call <font class="Apple-style-span" face="&#39;courier new&#39;, monospace">interprocess_condition::wait</font> or�<font class="Apple-style-span" face="&#39;courier new&#39;, monospace">interprocess_condition::time_ wait</font>�on the implementation lock which does all the work</li>
<li>unlock the internal�<span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">interprocess_mutex</span></li><li>relock the exclusive lock on��the�<span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">interprocess_upgradable_mutex</span>�</li>
</ul></div><div>Intuitively, this should work.</div><div><br></div><div>Is there anything I missed that would make this an incorrect implementation?</div><div><br></div><div>Cheers,</div><div><br></div><div>-John</div><div>
<br></div>