Subject: Re: [Boost-bugs] [Boost C++ Libraries] #7611: segfault in epoll_reactor.ipp
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-01-30 16:45:32
#7611: segfault in epoll_reactor.ipp
-------------------------------------------------+-------------------------
Reporter: Fredrik Jansson | Owner:
<fredrik.jansson.se@â¦> | chris_kohlhoff
Type: Bugs | Status: closed
Milestone: To Be Determined | Component: asio
Version: Boost 1.52.0 | Severity: Problem
Resolution: invalid | Keywords:
-------------------------------------------------+-------------------------
Comment (by anonymous):
Replying to [comment:5 anonymous]:
> Replying to [comment:4 jyu@â¦]:
> > In my case, the crash is due to two threads simultaneously closing the
socket. can you make the socket close or shutdown function thread-safe,
just as Fredrik Jansson suggested?
>
> You have a threading issue that's even worse than that of the original
poster. And it's your all your own fault.
>
> Here's how you can solve it: Use a mutex, such that you do NOT have 2
threads messing with the socket at the same time. (Within the protected
region, you could find out if the socket-descriptor is already closed, by
using something like descriptor.is_open() , see
http://www.boost.org/doc/libs/1_63_0/doc/html/boost_asio/reference.html#boost_asio.reference.posix__basic_descriptor.is_open
)
I ended up doing compare-and-swap on a flag to make sure the close-socket
is called only once.
Just wondering that the asio close-socket function may be thread-safe by
using the compare-and-swap on that crashing pointer.
In my app, only those thread-safe asio socket functions have been used
concurrently. I did not realized that the asio close-socket function is an
exception. My bad, I did not read the doc carefully.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/7611#comment:6> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC