Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous104
Beginner
100 Views

visibility and movable_exception

on Mac OS X with open source TBB 4.1 consider

class A { //copyable class, good for tbb::movable_exception
public:
   A(size_t n) : m_n(n) {}
   size_t getN() const {return m_n;}
private:
   size_t m_n;
};

class TBBTry {
public:
    void operator() ( const tbb::blocked_range<size_t>& r ) const {
        for ( size_t i = r.begin(); i != r.end(); ++i ) {
             if (((i+1) % 4) == 0) {
                size_t n = i + 100;
               throw tbb::movable_exception<A>(A(n));
            }
       } 
   }
   TBBTry() { }
};

int main() {
    try {
        tbb::parallel_for(tbb::blocked_range<size_t>(0, 5 ), TBBTry() );
    } catch ( tbb::movable_exception<A> &ex) {
        std::cout << "tbb::movable_exception n = " << ex.data().getN() << std::endl;
    } catch ( tbb::captured_exception &ex ) {
        std::cout << "tbb::captured_exception name = " << ex.name() << "; " << ex.what() << std::endl;
    } catch ( ... ) {
        std::cout << "unknown_exception" << std::endl;
   }
    return 0;
}


I expect to see
tbb::movable_exception n = 103

However I see the following output:
tbb::captured_exception name = N3tbb17movable_exceptionI1AEE; tbb::movable_exception

I debugged that issue and found out that we have problem with visibility template exception thrown from separate dll.

Problem is fixed if I do the following changes in the file
tbb_exception.h:

#ifndef __TBB_exception_H
#define __TBB_exception_H

# pragma GCC visibility push (default) //xxx(dmarkman)

...........

# pragma GCC visibility pop //xxx(dmarkman)

#endif /* __TBB_exception_H */

I sbmitted bug report but didn't get back any bugid and when I search bug db I'm getting no records

0 Kudos
3 Replies
100 Views

Hello, Thanks for the solution. could you submit a patch via contribution page http://threadingbuildingblocks.org/contribution_first.php? Bugzilla on our site is not very user-friendly now:) as far as I understand you have submitted 3 bugs: 197, 198, 199. thank you, --Vladimir
Recker
Beginner
100 Views

Is this problem fixed ? If so, can anyone point me to the release version when it was fixed ?

Thanks

Alexey_K_Intel3
Employee
100 Views

With std::exception_ptr available since C++11, TBB can propagate exceptions keeping their original types. For example, the code in question can be rewritten as

int main() {
    try {
        tbb::parallel_for(tbb::blocked_range<size_t>(0, 5 ),
        [] ( const tbb::blocked_range<size_t>& r ) {
            for ( size_t i = r.begin(); i != r.end(); ++i ) {
                if ( (i+1) % 4 == 0) {
                    throw A{i + 100};
                }
            }
        } );
    } catch ( A &ex) {
        std::cout << "exception A; n = " << ex.getN() << std::endl;
    } catch ( std::exception &ex ) {
        std::cout << "std::exception: " << ex.what() << std::endl;
    } catch ( ... ) {
        std::cout << "unknown exception" << std::endl;
    }
    return 0;
}

It makes the old TBB exception classes to be of no value; they will likely be deprecated, so you should better not use them these days.

For OS X /  macOS, exact exception propagation is supported since TBB 4.2.

Reply