Mixing Asynchronous Network I/O and POSIX Threads

John Baldwin jhb at freebsd.org
Mon Sep 19 12:41:20 UTC 2011


On Sunday, September 18, 2011 5:45:26 pm Richard Yao wrote:
> Dear Jilles,
> 
> I am using sigwaitinfo() with all interrupts masked to avoid the
> possibility of race conditions in signal handlers, but I have not used
> any realtime signals. Linux 2.6.35 found a way to invoke the SIGIO
> handler despite it being masked, but that issue would not occur under
> production conditions and that is a bug for a different mailing list.
> 
> Being unable to F_SETOWN individual threads would cause problems
> because it causes network traffic to become serialized. My code must
> run on Linux, but if I were to write FreeBSD-specific code so it would
> also work on FreeBSD, would using kqueue enable me to specify which
> threads handle events on specific file descriptors?

Yes in that you could give each thread its own kqueue fd and register other
fd's on the desired thread's kqueue.  However, Adrian's point about using
libevent is probably worth investigating to see if it will let you achieve
that in a portable way.

-- 
John Baldwin


More information about the freebsd-hackers mailing list