home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!cis.ohio-state.edu!eggplant.cis.ohio-state.edu!gyu
- From: gyu@cis.ohio-state.edu (george yu)
- Subject: How to avoid calling destructor twice after fork()?
- Message-ID: <1992Jul29.180655.4716@cis.ohio-state.edu>
- Originator: gyu@eggplant.cis.ohio-state.edu
- Sender: news@cis.ohio-state.edu (NETnews )
- Organization: The Ohio State University, Department of Computer and Information Science
- Date: Wed, 29 Jul 1992 18:06:55 GMT
- Lines: 28
-
- 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. The following figure shows the problem.
-
- class MY_CLASS;
- main()
- {
- MY_CLASS my_class;
-
- if(fork()==0)
- {
- // process 1
- }
- else
- {
- // process 2
- }
-
- // everything beyond this point will be executed twice, including
- // the destructor of my_class.
- }
-
- Any suggestions?
-
- Thanks in advance.
-
- George Yu
-