Date: Sat, 27 Feb 1999 20:27:13 +0000 (GMT) From: Terry Lambert <tlambert@primenet.com> To: jplevyak@inktomi.com (John Plevyak) Cc: hackers@FreeBSD.ORG Subject: Re: flock and kernel threads Message-ID: <199902272027.NAA13546@usr09.primenet.com> In-Reply-To: <19990223214744.A24606@proxydev.inktomi.com> from "John Plevyak" at Feb 23, 99 09:47:44 pm
next in thread | previous in thread | raw e-mail | index | archive | help
> I believe there may be a problem with lockfiles (flock) and > kernel threads. The problem is demonstrated by the enclosed > program, which if run twice will fail the second time. > > The problem seems to be that termination via signal of > the non-main thread (non-leader) does not (always) result > in a call to closef and hence a call to lf_clearlock. > > Suggestions, comments welcome. This happens because fd's are scoped to the process (it's an index intpo the per process open file table) and not to the thread that opened them. Consider that if they were scoped to the thread that did the open, you would not be able to do useful things like handing incoming socket connections off to worker threads. To resolve this, you either need to register a cleanup mechanism that knows about per thread state: man pthread_cleanup_push This is less than ideal, since it means that your threading architecture in your program is not very SMP scalable, by its design. In general, thread use should be limited as much as possible to a "work to do model", with any persistent state that will survive across transactions scoped globally in a per "session" state structure. Refeerences to the literature available on request (or you can scan the -current and -hackers list archives). Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199902272027.NAA13546>