home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.windows.x
- Path: sparky!uunet!era!feit
- From: feit@ERA.COM (Mark Feit)
- Subject: Re: fork and X
- Message-ID: <1992Jul31.145417.8778@ERA.COM>
- Sender: feit@ERA.COM (Mark Feit)
- Organization: Engineering Research Associates, Vienna, VA
- Date: Fri, 31 Jul 1992 14:54:17 GMT
- Lines: 59
-
- On comp.windows.x, tomasc@lionfish.tds.kth.se (Tomas Carlsson) posts:
- > I'm writing a program that needs to spawn children using a fork
- > and be able to talk to them using a pipe. My problems arise when
- > I want to spawn a second child. The first one is no problem.
- >
- > The first (X Windows-) thing a child does is make a fontcursor
- > and a pointergrab. This works fine for the first child but the
- > second one kills the whole family. I get these errors before
- > everything exits:
- >
- > X Error of failed request: BadIDChoice (invalid resource ID
- > chosen for this connection)
- > X Error of failed request: BadCursor (invalid Cursor parameter)
-
- Resource IDs are selected on the client side by an Xlib-internal
- routine called _XAllocID, which allocates a unique 32-bit ID based on
- some bitmasks acquired when the connection to the server was opened
- and a counter which gets incremented on each call. Whenever you make
- an Xlib call that creates a server resource (i.e., one from the
- XCreate* family), the routine calls _XAllocID for a new resource
- number before shipping its request off to the server. (IDs are a lot
- like files: The file system may create the file itself, but _you_ get
- to pick a name to identify it.)
-
- Your problem crops up as a result of the child processes having
- separate copies of _XAllocID's internal counter. For example, if the
- last resource ID allocated before you fork was abcd028, the first
- child will allocate abcd029. When you fork again (assuming no
- intervening calls to _XAllocID), the second child will get the same
- internal counter and will try to create something with an ID of
- abcd029, which the server chokes on because it's already been
- allocated.
-
- Off the top of my head, I can think of two solutions.
-
- - Allocate your resources before you fork and don't allocate
- anything in the children.
-
- - If you're not forking the same thing several times and your
- children allocate their own space to work with, switch to
- lightweight processes. (Less overhead there, too.)
-
- I've never really given much thought to how X programs that fork or
- are run on multiprocessor boxes should work, and perhaps I should
- since I may wind up having to deal with it sometime. I suppose
- isolating one copy if Xlib into an RPC service might be one way to go
- about it. Would anyone from the parallel computing world care to
- comment on how they handle things like this?
-
- - Mark
-
- ................................. .................................
- : Mark A. Feit, Software Engineer : Internet: feit@era.com :
- : Engineering Research Associates : USENET: ...!uunet!era!feit :
- ................................. .................................
- "Software development is 10% science, 25% ingenuity and 65% getting
- the ingenuity to work with the science."
-
-
-