Boost C++ Libraries: Ticket #5719: pthread mutex in getnameinfo_emulation https://svn.boost.org/trac10/ticket/5719 <p> In getnameinfo_emulation() a static pthread_mutex_t is initialized with PTHREAD_MUTEX_INITIALIZER, but pthread_mutex_init() is never called for the mutex. Although this may work on unix/linux, on other systems that emulate posix, pthread_mutex_init() must be called before the mutex is used, otherwise the underlying mutex is never created. </p> <p> Wouldn't it be better to use the wrapper class boost::asio::detail::posix_mutex instead of using posix directly? Actually, you can use boost::asio::detail::mutex instead and change the conditional macro to #if !defined(BOOST_WINDOWS). In addition, why not use a scoped lock (i.e. boost::asio::detail::mutex::scoped_lock) to perform the actual locking and unlocking of the mutex? Then you would only need one #if defined() instead of two. </p> <p> I have also attached a patch of the changes I described above. (Warning, I have not tried compiling with the changes, but you should get the idea) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5719 Trac 1.4.3 olim@… Tue, 19 Jul 2011 15:55:38 GMT attachment set https://svn.boost.org/trac10/ticket/5719 https://svn.boost.org/trac10/ticket/5719 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">socket_ops.ipp.patch</span> </li> </ul> Ticket chris_kohlhoff Tue, 29 May 2012 02:30:35 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5719#comment:1 https://svn.boost.org/trac10/ticket/5719#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> The whole point of PTHREAD_MUTEX_INITIALIZER is to statically initialise a mutex so that you don't need to call pthread_mutex_init. The POSIX spec for <a class="ext-link" href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_init.html"><span class="icon">​</span>pthread_mutex_init</a> says: </p> <blockquote> <p> In cases where default mutex attributes are appropriate, the macro PTHREAD_MUTEX_INITIALIZER can be used to initialize mutexes that are statically allocated. The effect shall be equivalent to dynamic initialization by a call to pthread_mutex_init() with parameter attr specified as NULL, except that no error checks are performed. </p> </blockquote> <p> What platform is this? If they require this then their POSIX emulation is broken. If you can supply more detail then I may consider a workaround. </p> Ticket