Hi,

I've been curious about how libuv works internally regarding thread 
communication.

This is what I understand:
There's a single thread running uv_run. If I spawn some work to be done 
in another thread I'm supposed to use uv_queue_work. The way to send 
the results of this work back to the main thread is through 
uv_async_send (which is the only thread-safe function in libuv).

This is what I want to do:
Start listening on a TCP socket, accept incoming connections in the 
default loop, and wait for data to be available for reading (using 
uv_read_start). When it's available for reading, I'd put the work 
(socket reading) in the queue (with uv_queue_work), and the callback 
for this would run in another thread, reading the data and performing 
some work based on it, which may involve writing data back to this or 
any other socket.

So, my questions related to this are:
- Is this possible to do? If I call uv_read_start and uv_write in 
another thread, can this cause trouble, because they should have been 
called in the default loop?

- If uv_read_start and uv_write should be called in the default loop, 
then the main thread will be responsible for reading and writing all 
data, right? Wouldn't this impact performance? How does NodeJS deal 
with this?

- How does uv_async_send work? From a quick glance at the source code, 
I suspect it sends data in a file descriptor, which will be read in the 
default loop. Is this what is happening?


Allan

-- 
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/groups/opt_out.

Reply via email to