Reuse of threads

Asked

Viewed 78 times

2

I’m making an addon for nodejs. One of the functions is responsible for parameterizing the incoming audio, from the various clients. I want this parameterization to be done in a thread.

void buffering(const FunctionCallbackInfo<v8::Value>& args) {

Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);

int size = args[1]->NumberValue();
int final_read = args[2]->NumberValue();
int inicio_read = args[3]->NumberValue();
int client_id = args[4]->NumberValue();

Local<Object> bufferObj = args[0]->ToObject();

buf = node::Buffer::Data(bufferObj);
char mini_buf[80000];//char mini_buf[4096];
memcpy(mini_buf, buf, size);
//Função para a correr numa nova thread
int teste_buf = Julius[client_id].Audio_Buffering(mini_buf, size, final_read, inicio_read, client_id);

If the Audio_Buffering were executed only once I could do as follows:

std::thread t[num__threads];
t[client_id] = std::thread(&SREngineJulius::Audio_Buffering, &Julius[client_id], mini_buf, size, final_read,inicio_read,client_id);

The problem is that this function, for the same client, will be run multiple times (until the customer stream is over). A solution would be to iterate and create new threads, but in the long run it would create a lot of junk. Any way to reuse a thread? Or create and destroy right away?

  • Can you explain what you want in the broadest sense? I mean, regardless of whether the thread will be used to process audio, or text, etc... What do you want? Is there a task to be performed from time to time? How does the program know when the thread should stop? Why would creating multiple threads generate garbage (if you can destroy them)? etc

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.