BRepAlgo_Common is not thread-safe

Hello OCCT Community,

In our project, we have developed an algorithm that scans all TopoDS_Shape objects (mainly imported from STEP files), check if there are any overlaps (non-empty intersection) among any two objects and send a warning to the user accordingly.

The easiest way we found to implement this, is by building the intersection between the shapes using the BRepAlgo_Common class. However, this process is very time consuming, therefore we tried to speed it up by running different intersections in parallel threads.

While testing this, however, we found out that the results were inconsistent, and sometimes the process even caused the application to crash. By digging into the issue, my colleague found out that this is probably due to the memory allocation management in some NCollection classes (invoked by BRepAlgo_Common) that is not developed to be thread-safe.

I would like to understand either:
1. if there are any plans to implement in future OCCT releases a thread-safe version of NCollection classes to be used by Boolean algorithms like BRepAlgo_Common;
2. if there are any suggestions to implement a check for overlaps using less time-consuming processes than BRepAlgo_Common.

Thank you in advance.

Dmitrii Pasukhin's picture

Hello, yes, we plan to improve thread-safaty of each algorithm. But it can be done only on logic level, not container.

Looks like that you are using old version of occt (7.4 or older). Please move to new version and check again.

Best regards, Dmitrii,

gkv311 n's picture

BRepAlgo_Common has been removed since OCCT 7.6 - please try porting to newer Boolean operations.

BRepAlgoAPI_Common already exposes flag BRepAlgoAPI_Common::SetRunParallel() for performing algorithm in multiple threads, when possible. Have you tried it?

If you have to implement multithreading in some other way - you need to share more logic to locate thread-unsafe places.

gkv311 n's picture

There is also a tool BRepExtrema_ShapeProximity for detecting intersactions between shapes without performing Boolean operation. This tool works on triangulated shapes, not on exact geometry.