Ticket #5351: 5351.diff

File 5351.diff, 2.9 KB (added by viboes, 11 years ago)

a possible solution

  • future.hpp

     
    66
    77#ifndef BOOST_THREAD_FUTURE_HPP
    88#define BOOST_THREAD_FUTURE_HPP
     9
    910#include <stdexcept>
    1011#include <boost/thread/detail/move.hpp>
    1112#include <boost/thread/thread_time.hpp>
     
    9394        {
    9495            boost::exception_ptr exception;
    9596            bool done;
     97            bool thread_was_interrupted;
    9698            boost::mutex mutex;
    9799            boost::condition_variable waiters;
    98100            typedef std::list<boost::condition_variable_any*> waiter_list;
     
    100102            boost::function<void()> callback;
    101103
    102104            future_object_base():
    103                 done(false)
     105                done(false),
     106                thread_was_interrupted(false)
    104107            {}
    105108            virtual ~future_object_base()
    106109            {}
     
    165168                {
    166169                    waiters.wait(lock);
    167170                }
     171                if(rethrow && thread_was_interrupted)
     172                {
     173                    throw boost::thread_interrupted();
     174                }
    168175                if(rethrow && exception)
    169176                {
    170177                    boost::rethrow_exception(exception);
     
    196203                boost::lock_guard<boost::mutex> lock(mutex);
    197204                mark_exceptional_finish_internal(boost::current_exception());
    198205            }
     206            void mark_interrupted_finish()
     207            {
     208                boost::lock_guard<boost::mutex> lock(mutex);
     209                thread_was_interrupted=true;
     210                mark_finished_internal();
    199211
     212            }
    200213            bool has_value()
    201214            {
    202215                boost::lock_guard<boost::mutex> lock(mutex);
    203                 return done && !exception;
     216                return done && !(exception || thread_was_interrupted);
    204217            }
    205218            bool has_exception()
    206219            {
    207220                boost::lock_guard<boost::mutex> lock(mutex);
    208                 return done && exception;
     221                return done && (exception || thread_was_interrupted);
    209222            }
    210223
    211224            template<typename F,typename U>
     
    12301243                {
    12311244                    this->mark_finished_with_result(f());
    12321245                }
     1246                catch(thread_interrupted& it)
     1247                {
     1248                    this->mark_interrupted_finish();
     1249                }
    12331250                catch(...)
    12341251                {
    12351252                    this->mark_exceptional_finish();
     
    12561273                    f();
    12571274                    this->mark_finished_with_result();
    12581275                }
     1276                catch(thread_interrupted& it)
     1277                {
     1278                    this->mark_interrupted_finish();
     1279                }
    12591280                catch(...)
    12601281                {
    12611282                    this->mark_exceptional_finish();