Subject: stdio locking
To: None <>
From: Michael Graff <>
List: tech-userlevel
Date: 12/15/1999 20:12:18
How should locking be added to stdio?

There are functions (flockfile() and funlockfile()) which userland
code can call to lock stdio information.  However, the actual
underlying mutex has to go somewhere.

There are serious problems with adding a new element to the FILE
type.  Namely, all hell breaks lose, since many things refer to
stdout, stderr, and stdin -- which are all members of an array, and
the offsets in that array are of course compile-time computed.

I see two options:

	Add a void * pointer in libc, and use it to point to the
	malloc'd lock.


	Build a hashed list of file *'s and their associated locks.

The latter is what FreeBSD did.  BSDI did the former, and added 4
bytes of "padding crock" (which I assume is for future expansion)