Hi, On 03/05/2014 11:04 AM, Thiago Arruda wrote:
I have a libuv event loop running in a background thread, it's reading from stdin and filling a buffer read by the main thread.There's an 'exit' function called by the main thread that does some cleanup including these lines: /* stop libuv loop */ uv_async_send(&stop_loop_async); /* wait for the event loop thread */ uv_thread_join(&io_thread); The 'stop_loop_async' is configured to call a function that will call 'uv_stop' on the background thread. That wont work when libuv is polling for data and the program will block forever in `uv_thread_join`. Here's the backtrace of the hanging program:
What do you mean by "won't work"? Is the async callback executed? If so, libuv is executing that callback and not polling for i/o, and when uv_stop is called the next time a 0 timeout poll will be performed.
thread 1: #0 0xb77a4424 in __kernel_vsyscall () #1 0xb7751e1c in pthread_join (threadid=3073854272, thread_return=0x0) at pthread_join.c:89 #2 0x081fc309 in uv_thread_join (tid=0x826b5a0) at src/unix/thread.c:35 thread 2(the event loop thread): #0 0xb77a4424 in __kernel_vsyscall () #1 0xb77579db in read () at ../sysdeps/unix/syscall-template.S:82 #2 0x081fa4c3 in read (__nbytes=<optimized out>, __buf=<optimized out>, __fd=<optimized out>) at /usr/include/i386-linux-gnu/bits/unistd.h:45 #3 uv__read (stream=0x826b680) at src/unix/stream.c:1001 #4 uv__stream_io (loop=0xb6a00468, w=0x826b6b8, events=1) at src/unix/stream.c:1146 #5 0x081ff35e in uv__io_poll (loop=0xb6a00468, timeout=-1) at src/unix/linux-core.c:271 #6 0x081f6252 in uv_run (loop=0xb6a00468, mode=UV_RUN_DEFAULT) at src/unix/core.c:284 The libuv version is 0.11.19 and operating system is linux 32 bits. What would be the best way to deal with the problem?
Do you have a test case showing this behavior? By looking at the code I don't see how this could happen.
Cheers, -- Saúl Ibarra Corretgé bettercallsaghul.com -- 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.
