> 1. From an async worker thread if the binding function that reads a
> tag asynchronously is used.
> Now since any JS code needs to run in the main thread, here is what I do:
> - In the worker thread, I lock a mutex, then use uv_async_send to
> notify the main event loop. Then the worker
> thread tries to lock the mutex again and is blocked. The
> async watcher triggers the JS function from (1) in the main thread,
> then unlocks the mutex so that the worker
> thread can continue. This works perfectly.

I don't think it is safe to acquire a mutex with one thread and then
have it released by another. (with semaphores this is okay btw.)

But you could use pattern like this (pseudocode alert):

function ReadTagImpl(input) {
  ...
}

static result;

function ReadTagWork(work_item) {
  result = ReadTagImpl(work_item.input);
  AcquireMutex();
  uv_async_send()
}

function ReadTagAsync(args) {
  work_item = ...
  uv_queue_work(ReadTagWork, work_item)
}

function ReadTagSync(args) {
  return ReadTagImpl(args);
}

-- 
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

Reply via email to