home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!darwin.sura.net!mips!swrinde!sdd.hp.com!hplabs!hplextra!otter.hpl.hp.com!hpltoad!cdollin!kers
- From: kers@hplb.hpl.hp.com (Chris Dollin)
- Newsgroups: comp.lang.c++
- Subject: Re: How to avoid calling destructor twice after fork()?
- Message-ID: <KERS.92Jul30173512@cdollin.hpl.hp.com>
- Date: 30 Jul 92 16:35:12 GMT
- References: <1992Jul29.180655.4716@cis.ohio-state.edu> <1992Jul30.120150.1507@actrix.gen.nz>
- Sender: news@hplb.hpl.hp.com (Usenet News Administrator)
- Organization: Hewlett-Packard Laboratories, Bristol, UK.
- Lines: 95
- In-Reply-To: Bruce.Hoult@bbs.actrix.gen.nz's message of 30 Jul 92 12:01:50 GMT
- Nntp-Posting-Host: cdollin.hpl.hp.com
-
- In article ... Bruce.Hoult@bbs.actrix.gen.nz writes:
-
- [quoting someone else]
- > I am using fork() system call in my C++ program. The problem is that each
- > calling of fork() creates a copy of calling process. The problem is any
- > instances created and not destroyed before fork() calling will be
- > destroyed twice. [comiited]
-
- What's the problem? After the fork you've got two seperate objects in
- different processes and running the destructor on both of them is the
- correct thing to do -- the only possible problem is that the fork()
- call effectively does a default operator= to create the second copy
- instead of using any operator= that you've defined.
-
- That's all very well, but what if the objects are hanging on to an external
- resource, such that the destructor does something *external*? For example, a
- Window object might have an X window handle, and the destructor might destroy
- the window. What happens if you try and destroy a destroyed window? Will the
- code abort (so what happens to the other destructores - do they get run, too)?
- Or will the server happily delete a new window that's been allocated the same
- handle? The same with a lock file object - it might be a new lock (probably
- shouldn't be, but it might).
-
- No, it's not that easy.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- --
- Bruce.Hoult@bbs.actrix.gen.nz Twisted pair: +64 4 477 2116
- BIX: brucehoult Last Resort: PO Box 4145 Wellington, NZ
- "Cray's producing a 200 MIPS personal computer with 64MB RAM and a 1 GB
- hard disk that fits in your pocket!" "Great! Is it PC compatable?"
- --
-
- Regards, | It's strange how you suddenly discover bizarre and dangerous
- Kers. | holes in your knowledge. I fell down one today. - Steve Knight
-