Invoke DLL in slave threads - ramdom crash

Hi,

I was able to find good refereences on q’s C API as well q’s multithreading (via q -s n) features. But I have not been able to find any solid reference regarding the interaction between DLL functions and slave threads. May I know if there is any reference on things to pay attention to when calling an external function within peach call?

A simple case is:

q script.q -s 8

And running script.q as:

fun:ext_fun 2:(C_fun;1)fun peach 1000?8`

Assuming the external function C_fun requires a lot of interactions with C API (a lot of ktn/knk/etc. calls) in order to construct the final result.

What I’m facing is that the above fun runs fine with “fun each 1000?8</font>" but crashes randomly with "<font face='"courier' new monospace>fun peach 1000?8”.

I tried to remove the final steps in C_fun that calls ktn/knk/etc. to construct the resultset, then peach is running fine, too. (Presumingly, all the other computations involved were running fine in multithreading mode.) But I couldn’t pinpoint why constructing the result structure can cause problem. 

Does calls to ktn/knk/etc. memory allocation routines in k.h require special protection when running in multithreads?

Thanks in advance for any pointers on this topic.

using the c-api should be fine from different threads within peach.

is your C_fun thread-safe? Can you post a small but complete example which reproduces the crash?

Which version/release/platform of kdb+ are you running?

thanks