Replicating an instance in a multi-threaded app
-
Hello, How do I do about making an app replicate itself whenever a particular event occurs? The application I have in hand is a multi-threaded one, which, at some point in time, has to create a new instance of itself dynamically and automatically, thereby replicating itself, with no user input whatsoever. Can someone shed some light on the correct way to do this? Thanks a lot.
-
Hello, How do I do about making an app replicate itself whenever a particular event occurs? The application I have in hand is a multi-threaded one, which, at some point in time, has to create a new instance of itself dynamically and automatically, thereby replicating itself, with no user input whatsoever. Can someone shed some light on the correct way to do this? Thanks a lot.
That depends on what you mean by 'an app replicate itself'. If you mean having a second process running the same code, in the same state, then you need to use
CreateProcess()
to start a second instance of your application, and pass sufficient information to the second instance for it to initialize itself to the same condition as the original. This will include information that lets you start an equivalent set of threads. This information could be passed in a file on the command line, or through some inter-process communication mechanism. If you're looking for an API function like 'CreateDuplicateProcess()
', I'm afraid you're out of luck.
Software Zen:
delete this;
-
That depends on what you mean by 'an app replicate itself'. If you mean having a second process running the same code, in the same state, then you need to use
CreateProcess()
to start a second instance of your application, and pass sufficient information to the second instance for it to initialize itself to the same condition as the original. This will include information that lets you start an equivalent set of threads. This information could be passed in a file on the command line, or through some inter-process communication mechanism. If you're looking for an API function like 'CreateDuplicateProcess()
', I'm afraid you're out of luck.
Software Zen:
delete this;
Thanks for the tip, Gary. Will take a look at
CreateProcess
and see if it allows me to accomplish what I need to. David