c++ - Call not thread-safe DLL function from Java's multi threads in parallel -


although c++ program not thread-safe, need call java's multiple threads in parallel. can not rewrite c++ code , need execute dll created compiling c++ program in parallel due performance issue.

how call not thread safe c++ function java's multi-threads?

what i've tried using jna , call native#loadlibrary every time when thread calls dll function. but, not solve problem , occurs segmentation fault.

public static class myrunnable implements runnable{   ...   public void run(){     myclibrary instance = (myclibrary)native.loadlibrary(myclibrary.jna_library_name, myclibrary.class);     instance.cfunc()   }     ... } 

i thought new memory space dll allocated calling native#loadlibrary , reentrant issue should avoided. but, thought might fault.

i searched correct way create multiple memory space dll java, not find it.

how call not thread safe c++ function java's multi-threads?

you can't. can't because c++ function not thread-safe1.

i searched correct way create multiple memory space dll java, not find it.

there isn't way that. (afaik)

your options are:

  • restrict calls c++ function single java thread ... or 1 thread @ time. (not acceptable, , in latter case, possibly unsafe.)

  • launch multiple child processes (each) run c++ application calls function. pass arguments , results via process pipes or using network messages, rpc, etcetera. (problem java app <--> c++ app information passing performance bottleneck.)

  • rewrite c++ code make thread-safe.

the last approach give best performance.


1 - possibly overstates case. may depend on why c++ function not thread-safe. if issue ... suspect ... function use static variable hold state, situation state.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -