Boost logo

Boost :

From: Oliver.Kowalke_at_[hidden]
Date: 2007-03-15 03:24:43


Hello,

> I've made a futures implementation in the hopes of combining
> the best features from all the proposals and various
> implementations currently floating around. It is still rough
> around the edges, but is mostly covered by unit tests.
>
> http://braddock.com/~braddock/future/
>
> I'm looking for input. I'd be willing to add additional
> functionality needed and progress it to the point where it
> could be formally submitted into boost if there is interest.
> It could perhaps be merged into the existing futures
> implementation in the vault to add combined groups, etc.
>
> I used Peter's exception_ptr code, which he said he would
> post under a boost license.
>
> -Braddock Gaskill

I've tested your implementation with a thread and I get sometimes an
segmentation fault (linux, gcc-4.1.0).
File future_detail.hpp line 79 causes the segmentation fault.
Regards, Oliver

Code:

#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <string>

#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/thread.hpp>

#include "future.hpp"

struct X
{
        std::string execute()
        { return "std::string X::execute()"; }
};

void execute(
        boost::promise< std::string > p,
        boost::function< std::string() > fn)
{ p.set( fn() ); }

int main( int argc, char *argv[])
{
        try
        {
                X x;
                boost::function< std::string() > fn(
                        boost::bind(
                                & X::execute,
                                x) );
                boost::promise< std::string > p;
                boost::future< std::string > f( p);
                boost::thread t(
                        boost::bind(
                                & execute,
                                p,
                                fn) );

                std::cout << f.get() << std::endl;

                t.join();

                return EXIT_SUCCESS;
        }
        catch ( std::exception const& e)
        { std::cerr << e.what() << std::endl; }
        catch ( ... )
        { std::cerr << "unhandled exception" << std::endl; }

        return EXIT_FAILURE;
}

Gdb:

Program terminated with signal 11, Segmentation fault.
#0 basic_string (this=0xbff79740, __str=@0x0) at
/opt/gcc-4.1.2-src/src/i486-linux-gnu/libstdc++-v3/include/bits/basic_st
ring.h:283
283
/opt/gcc-4.1.2-src/src/i486-linux-gnu/libstdc++-v3/include/bits/basic_st
ring.h: Datei oder Verzeichnis nicht gefunden.
        in
/opt/gcc-4.1.2-src/src/i486-linux-gnu/libstdc++-v3/include/bits/basic_st
ring.h
(gdb) bt
#0 basic_string (this=0xbff79740, __str=@0x0) at
/opt/gcc-4.1.2-src/src/i486-linux-gnu/libstdc++-v3/include/bits/basic_st
ring.h:283
#1 0x0804d8da in boost::detail::future_impl::get<std::string>
(this=0x8055048, value=0x0) at
/home/kowalke/Projects/test_future/src/future_detail.hpp:79
#2 0x0804d94b in boost::future<std::string>::get (this=0xbff796c4) at
/home/kowalke/Projects/test_future/src/future.hpp:210
#3 0x0804a007 in main () at
/home/kowalke/Projects/test_future/src/test.cpp:43


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk