Answer the question
In order to leave comments, you need to log in
How to call a function in parallel so that it survives after the calling function ends?
I am writing a dll for an external program.
The a(string str) function in Dll must accept strings, save them to a vector, process the accumulated data after X milliseconds and pass the result to the b(string result) function, which sometimes saves it to SharedMemory, and sometimes to the database.
The data comes very often, i.e. the function can be called hundreds of times per second.
Waiting for SharedMemory to be released or for a query to the database to pass is very long, so I want to send the result of processing from a() to b() and immediately return from a().
1. Is it possible that with such a frequent function call, the data in the vector will be distorted or not completely written? The order of the entries is not important.
2. How to release the function b(result) into free swimming? At first I thought to do
thread th(b);
th.detach();
but then I realized that if it was a regular program, and not a dll, then th would not have had time to complete it, because the calling function would have ended.
I suppose that in dll, as well as in exe, it also will not have time to complete it.
Do I understand correctly that the only solution for b(result) to finish when a(str) has already ended and returned control is to write a separate exe for b() and run it as a separate process?
Answer the question
In order to leave comments, you need to log in
1. Is it possible that with such a frequent function call, the data in the vector will be distorted or not completely written? The order of the entries is not important.
How to release the function b(result) into free swimming? At first I thought to do
thread th(b);
th.detach();
but then I realized that if it was a regular program, and not a dll, then th would not have had time to complete it, because the calling function would have ended.
I suppose that in dll, as well as in exe, it also will not have time to complete it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question