Multi-threading with SketchUp C SDK

I have been trying to find information on multi-threading support in SU C SDK, but so far without success. So I’m posting my question here: are SU C SDK functions in general re-entrant (i.e. can I call them from multiple threads without protecting them with any kind of synchronization mechanism)? If some are, and some aren’t, then it would be nice to now which are which.

I have done some experiments with calling SUFaceGetFrontMaterial, SUFaceGetUVHelper, SUMeshHelperCreateWithUVHelper, SUMeshHelperGetNumVertices, SUMeshHelperGetVertices, SUMeshHelperGetNormals, etc. on separate faces (while also providing separate instances for material references, vertex and normal arrays, etc.) from multiple threads in parallel without any issues, but I would like to know if this is safe by design or I’m just being lucky so far.

The reason for doing what I’m trying to do is speed. According to my profiling results, the triangulation of faces in SU (in particular, calling the SUMeshHelperCreateWithUVHelper function) is taking quite a bit of time, and parallelizing this operation over multiple faces speeds things up considerably (30% to 40% in my use case).


THIS POST, from the Sketchup team, may help explain things.

See what ThomThom has said in the past …

Reading from multiple threads might not be that dangerous.
You can always put the sdk calls in a mutex and let the rest of the internal calculations run parallel.

SketchUp is not thread safe. The C API inherits this.

But you might be able to use multiple threads to read from a model.

I say “might” because if you are using the C API within SketchUp itself (via a Ruby C Extension) then there might be cache invalidation that throws a spanner in the works - depending on how to read.

In the standalone C API (using outside of SketchUp - via SketchUpAPI.lib) then you should be fine. If you use it within SketchUp (Live C API - via sketchup.lib) then you are probably fine as long as you use the main thread to join the child-threads. Doing so should prevent SU from being able to update anything while you read.

This isn’t something we have tested - so mileage may vary.

1 Like