On Tue, Aug 28, 2012 at 2:47 PM, Shea Levy <[email protected]> wrote: > Hello, > > I would like to write a javascript wrapper around uv_queue_work to deal with > the case of computationally-expensive functions that shouldn't run in the > event loop. While obviously this is potentially dangerous, well-written code > could ensure that the callback called does not touch any state that could > also potentially be viewed in parallel in the event loop. An example might > be: > > function addInBackground(a,b,cb) { > var add; > add = function() { > return a + b; > } > uv_queue_work(add,cb); > } > > I know that in my naive guess on how threading could work, this particular > usage should be safe. My question is: under the hood, is it possible that > calling the 'add' callback from the work_cb function of uv_queue_work > manipulates some v8 state in an unsafe way?
Fedor's reply is perhaps a little terse. The answer is "don't do that", V8 is not thread safe. You can run JS code in a separate V8 isolate (essentially a separate VM) but that only works for code that doesn't need to interact with the outside world. -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
