Reusing threads

2

I'm making an addon for nodejs. One of the functions is responsible for making parameterizations the incoming audio of the various clients. I want this parameterization 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 Audio_Buffering was run only once, I could do it 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 executed multiple times (until the client stream is terminated). One solution would be to iterate and create new threads, but in the long run this would create a lot of junk. Any way to reuse a thread? Or create and destroy right away?

    
asked by anonymous 22.10.2015 / 15:29

0 answers