threads

i’m interfacing with a 3rd party library that uses a separate thread for setting timers for running callbacks.  i’m writing a c client (linking with c.o) and i’m hoping to get some tips on coding in c with threads.

i don’t get many hits on the code.kx.com wiki (see below)

what k.h functions are thread safe or reentrant?  any locking needed?

can khp() be called on separate threads?  (i note that khp it is an initialization function as well as a connection function).

for shared objects, can k(0..) be called on separate threads?  for clients, can k([-]c..)?

can K vars be shared between threads?  is r1/r0 thread safe?  

i note that b9 can be called to send data to other threads http://code.kx.com/wiki/Cookbook/InterfacingWithC#Serialization.2FDeserialization  

http://code.kx.com/wiki/Cookbook/InterfacingWithC says
  "Note that k objects must be freed from the thread they are allocated within, and m9() should be called when the thread is about to complete, freeing up memory allocated for that thread’s pool.

ta, jack

As mentioned in your last paragraph below, it’s not safe to manipulate structure pointed to by K in a thread other than the main one.

In my experience with interfacing with 3rd-party libraries, I always serial and send the data back to the main thread for processing before the data structure gets returned to q.