RE: Who changed /proc// in 2.6.0-test5-bk9?

Linus Torvalds
2003-10-08T00:54:55Z

On Tue, 7 Oct 2003, Robert White wrote:
>
> What is gained by having the independent file descriptor context that would
> be *broken* for lack of that independence?

You're coming at it from the wrong end. Sharing resources is inherently
bad. If there is no reason to share, you shouldn't share.

The reason people use threads is that sharing the VM space has real
advantages: it makes context switching much cheaper (fewer hw resources in
the form of TLB usages) and it allows for much faster synchronization
through a shared address space.

But the same isn't true of file descriptors or a lot of other software-
level abstractions. There are no inherent advantages to sharing, and in
fact sharing just gives more opportunity for race conditions, bad
interaction etc.

For example, one reason _not_ to share is that the subthread may want to
be as invisible to the "main thread" as possible. That's just good
programming practice - trying to isolate and encapsulate as much data as
possible.

The same way you shouldn't make all your variables global, you shouldn't
make all your data structures global unless you have a reason.

Linus