Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.

visibility and movable_exception

Anonymous104
Beginner
256 Views

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
Vladimir_P_Intel2
256 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
256 Views

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

Thanks

Alexey_K_Intel3
Employee
256 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