Is BRepAlgo_Section thread-safe ?

Hello,

I'm using BRepAlgo_Section concurrently with std::async(...) and it crashes. Of course it doesn't with single-threaded execution.

Is BRepAlgo_Section supposed to be thread-safe or not ? I guess not but just asking to be sure.

See the call-stack in the attached piece, by the way I'm using OpenCascade 7.3.0 and VS2017.

Kirill Gavrilov's picture

I'm not sure I understand how you are trying using BRepAlgo_Section with std::async.
Maybe you could share a code quotation clarifying your context?

Hugues Delorme's picture

Hello Kirill,

    Yes sure, see this snippet

Kirill Gavrilov's picture

OK, I see now - you are creating a dedicated BRepAlgo_Section instance taking the same input TopoDS_Shape.
And here we have two items for concurrency:
- Does BRepAlgo_Section use any global-state variables? I believe it doesn't.
- Does BRepAlgo_Section modifies the input shape? Actually it could - non-destructive principle introduced within OCCT 7.0.0 is not enabled by default (#0027049).

So at first you may try enabling SetNonDestructive() flag in Boolean algorithm
(note that BRepAlgo_Section is marked as deprecated, you will find this flag only using non-deprecated API BRepAlgoAPI_Section).
If it still crashes - you may prepare a reproducible test case and register an issue on Bugtracker.
To check if the issue is due to (concurrent) modification of input shape, you may add a code making a deep copy of TopoDS_Shape before putting it to Boolean algorithm.

Note that Boolean operations in OCCT have some built-in mutli-threading support, and building preliminary structures for the input shape may take considerable time;
you may consider alternative ways for performing big number of sections in more efficient way using OCCT API.

Hugues Delorme's picture

Hello Kirill,

    Following your instructions, I simply used BRepAlgoAPI_Section instead of BRepAlgo_Section, and it works without crashes now!

Thanks for the help!