I am trying to write a dynamic native library using c++ which will be used with c# applications.
The issue is am very confused about returning results from native lib. the thing is I need to create a thread inside the native lib. So the function inside the native livrary must create and return bool (or something else) the thread is created.
When the native thread is done, I need to pass the calculated data lets consider a single structure made with multiple integers to the native app.
so far I came up with 2 idea:
1- add a callback function parameter to the thread starting function and return true if thread started. and add another native function to try fetch the thread results, returns bool if thread finished, gets a struct reference parameter to fill it if thread is done. But still callback function is called inside the thread, so I need to code a lot to provent thread collisions from c# app.
2- returning an unique id(if thread not done -1, else 2) from native thread starting function, and one more for getting data like: bool(if thread done true, else false) GetThreadResult(int thread-id, void**(rawData(if thread not done nullptr else dataptr into void*)); how ever with a big thread based native lib, this will get complicated I think.
please forgive me if I am nonsense or unclear, not been too long starting nativeC++/C# concept.
I am sure there must be a more clever way to accoplisg this, I need some suggestion.
manys thanks for reading this long confused message, and any comments!