Opened 11 years ago

Closed 10 years ago

#5719 closed Bugs (invalid)

pthread mutex in getnameinfo_emulation

Reported by: olim@… Owned by: chris_kohlhoff
Milestone: Boost 1.48.0 Component: asio
Version: Boost 1.47.0 Severity: Problem
Keywords: Cc:

Description

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.

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.

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)

Attachments (1)

socket_ops.ipp.patch (1.9 KB ) - added by olim@… 11 years ago.

Download all attachments as: .zip

Change History (2)

by olim@…, 11 years ago

Attachment: socket_ops.ipp.patch added

comment:1 by chris_kohlhoff, 10 years ago

Resolution: invalid
Status: newclosed

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 pthread_mutex_init says:

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.

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.

Note: See TracTickets for help on using tickets.