Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Jul 2004 15:20:57 +0400 (MSD)
From:      Igor Sysoev <is@rambler-co.ru>
To:        Paul Querna <chip@force-elite.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: KQueue and Threads?
Message-ID:  <20040719150946.S38581@is.park.rambler.ru>
In-Reply-To: <1090133387.16090.45.camel@localhost>
References:  <1090133387.16090.45.camel@localhost>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 17 Jul 2004, Paul Querna wrote:

> I have a question about using KQueue() in multi-threaded situations. A
> couple months ago I wrote the KQueue support for Apache2/APR. I am now
> investigating a pseudo Event/Worker MPM to better handle KeepAlive
> Requests. (support for KQueue in Apache is available in our CVS HEAD and
> via an experimental patch in the FreeBSD Ports...  Feedback would be
> nice.)
>
> For my example, say I have two threads.
>
> Thread A is in a kevent() waiting for events to happen on a set of FDs.
> Thread B has an FD that it would like to add to the KQueue that Thread A
> is using.
>
> What is the best way to get that FD into the KQueue, avoiding as much
> context switching as possible?
>
> Is it possible for Thread B to just call kevent w/ EV_ADD and Thread A
> will get proper notifications from that FD in the changed KQueue?

Yes, it's possible for kqueue. I use this behaviour in my multi-process
and multi-threaded light http and reverse-proxy server nginx. Thread B can
successfully add at least the EVFILT_READ and EVFILT_WRITE filters.
rfork()ed threads can not add EVFILT_SIGNAL.

> I know this is possible with Linux's sys_epoll() implementation. Other
> threads can just add FDs to the epoll, and the thread waiting in the
> epoll will get notified of any activity on those new FDs, just like the
> existing FDs.

RT signals in Linux 2.6 and epoll support this feature too.

In Linux 2.4 clone()ed threads can not add signal notification for
another thread, because they have the different pids and a kernel
returns EPERM for fcntl(F_SETOWN).


Igor Sysoev
http://sysoev.ru/en/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040719150946.S38581>