Hello again. Thanks for your help I really appreciate your responses. I found the solution! Apparently the worker releases memory by itself after the job is done, so I can keep doing it this way. The memory leak was my code's fault, since I was allocating memory and not releasing it somewhere else (totally hidden I didn't see it), but now it's solved.
Sorry for giving an incomplete code (I was trying to keep it clean and simple for the question). El martes, 27 de octubre de 2015, 16:01:27 (UTC+1), Ben Noordhuis escribió: > > On Mon, Oct 26, 2015 at 2:50 PM, Karim Benjelloun Herrera > <[email protected] <javascript:>> wrote: > > Hello everyone, I have a question that I still haven't found the > solution > > for it. So I would like to ask here if someone knows how to solve it. > > > > I am making a C++ addon for Node. And I would like to run uv_queue_work > > multiple times without having to use a while/sleep the main thread. Any > idea > > of how to do this? > > > > So far I've done this: > > > > void main(const FunctionCallbackInfo<Value>& args) { > > //here goes my main code > > > > //Here I schedule the worker, to run BEFOREmethod in a new thread, and > > AFTERmethod in the main thread > > uv_queue_work(uv_default_loop(), req, BEFOREmethod,(uv_after_work_cb) > > AFTERmethod); > > > > return callback; > > } > > > > > > > > void BEFOREmethod(uv_work_t* req){ > > > > //here goes the code that runs in new thread > > usleep(200000); > > } > > > > > > > > > > void AFTERmethod(uv_work_t* req, int status){ > > > > //here goes the code that runs in main thread > > > > //Then we schedule the uv_queue_work again > > uv_queue_work(uv_default_loop(), req, BEFOREmethod,(uv_after_work_cb) > > AFTERmethod); > > } > > > > So this works, I can re-schedule the uv_queue_work, but there is a > memory > > leak, if I keep this running, memory usage keeps increasing. But I > haven't > > found another way of doing this. So I would appreciate any help if > anybody > > has an idea. > > > > Thanks in advance! > > > > > > Karim > > It's hard to tell what is going on, the code you posted is obviously > incomplete. `req` is not defined anywhere, for example. > -- You received this message because you are subscribed to the Google Groups "libuv" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/libuv. For more options, visit https://groups.google.com/d/optout.
