Opened 11 years ago
Closed 10 years ago
#5719 closed Bugs (invalid)
pthread mutex in getnameinfo_emulation
Reported by: | 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)
Change History (2)
by , 11 years ago
Attachment: | socket_ops.ipp.patch added |
---|
comment:1 by , 10 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
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:
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.