scanpat
scanpat

Reputation: 319

multi-threading in a not thread-safe environnement

In my c++ program, I use a proprietarry library (.dll) which is not thread-safe. :-(

In this library there is a specific scientific computing.

Is there a way to safety start several computing of this library in parallel with threads ? (1 process, many threads)

My program "is like" a "for" loop on which call each time the computing of my not thread-safe library

Upvotes: 0

Views: 176

Answers (2)

minjang
minjang

Reputation: 9050

A very simple approach would be forking multiple slave processes in your for loop. The slave process loads the non-thread-safe module and does computations, and finally returns the result to the parent process via either a simple return code (if the result fits into 4 bytes), IPC, or file.

Of course, this approach assumes that the parallel computations do not need any interaction with the others.

Upvotes: 1

mkluwe
mkluwe

Reputation: 4061

Sounds like you want to load the DLL multiple times. Take a look at Load the same dll multiple times.

Upvotes: 2

Related Questions