[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-hackers
Subject:    Re: flock and kernel threads
From:       Terry Lambert <tlambert () primenet ! com>
Date:       1999-02-27 20:27:13
[Download RAW message or body]

> 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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic